Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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