Skip to content

Commit

Permalink
feat: add sync token set/get methods (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda authored Sep 30, 2024
1 parent 7199863 commit d949397
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/read-your-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,29 @@ describe("Read Your Writes Feature", () => {
const updatedSync = redis.client.upstashSyncToken;
expect(updatedSync).not.toEqual(initialSync);
});

test("should updat read your writes sync token using set/get", async () => {
const redis = new PublicRedis({
url: process.env.UPSTASH_REDIS_REST_URL,
token: process.env.UPSTASH_REDIS_REST_TOKEN,
});

// should change from "" to string
expect(redis.readYourWritesSyncToken).toBe("");
await redis.set("key", "value");
expect(redis.readYourWritesSyncToken).not.toBe("");
expect(typeof redis.readYourWritesSyncToken).toBe("string");

// should change after set
const syncToken = redis.readYourWritesSyncToken;
await redis.set("key", "value");
expect(syncToken).not.toBe(redis.readYourWritesSyncToken);

// should be able to set
const newSyncToken = "my-new-sync-token";
redis.readYourWritesSyncToken = newSyncToken;
expect(redis.readYourWritesSyncToken).toBe(newSyncToken);

await redis.set("key", "value");
});
});
8 changes: 8 additions & 0 deletions pkg/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ export class Redis {
this.enableAutoPipelining = opts?.enableAutoPipelining ?? true;
}

get readYourWritesSyncToken(): string | undefined {
return this.client.upstashSyncToken;
}

set readYourWritesSyncToken(session: string | undefined) {
this.client.upstashSyncToken = session;
}

get json() {
return {
/**
Expand Down

0 comments on commit d949397

Please sign in to comment.