-
Notifications
You must be signed in to change notification settings - Fork 87
DX-1019: Read Your Writes Support #1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fahreddinozcan
merged 23 commits into
main
from
dx-1019-redis-sdks-read-your-writes-support
Jul 30, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
37b8f37
add: readYourWrites option interface
fahreddinozcan bcdd601
send local sync token on requests
fahreddinozcan 105bffd
fmt
fahreddinozcan 6f9ca94
add promise.all tests
fahreddinozcan 963abae
add: lua script test
fahreddinozcan cf10255
format tests
fahreddinozcan eed34df
fmt
fahreddinozcan 74c005c
change upstashSyncToken convention
fahreddinozcan 5e86304
add public redis client test
fahreddinozcan d84dfed
add: fastly and cloudflare clients ryw support
fahreddinozcan e1fc32a
fmt
fahreddinozcan d6b3307
add default test
fahreddinozcan 4eb9e4d
add: comments
fahreddinozcan b563e66
add: http comment
fahreddinozcan b21bff1
sync token docs
fahreddinozcan 5be9815
remove comment
fahreddinozcan 14fd82c
fix readYourWrites arg comment
fahreddinozcan 1525179
Merge branch 'main' into dx-1019-redis-sdks-read-your-writes-support
fahreddinozcan ac49c85
Merge branch main of https://github.com/upstash/redis-js into dx-1019…
fahreddinozcan 13aba1e
Merge branch dx-1019-redis-sdks-read-your-writes-support of https://g…
fahreddinozcan f3497aa
add: ryw operation comments
fahreddinozcan 7332909
revert requester
fahreddinozcan 60233cb
revert requester interface
fahreddinozcan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { keygen, newHttpClient } from "./test-utils"; | ||
|
|
||
| import { afterAll, describe, expect, test } from "bun:test"; | ||
|
|
||
| import { Redis as PublicRedis } from "../platforms/nodejs"; | ||
| import { SetCommand } from "./commands/set"; | ||
| import { Redis } from "./redis"; | ||
|
|
||
| const client = newHttpClient(); | ||
| const { cleanup } = keygen(); | ||
| afterAll(cleanup); | ||
| describe("Read Your Writes Feature", () => { | ||
| test("successfully retrieves Upstash-Sync-Token in the response header and updates local state", async () => { | ||
| const initialSync = client.upstashSyncToken; | ||
| await new SetCommand(["key", "value"]).exec(client); | ||
| const updatedSync = client.upstashSyncToken; | ||
| await new SetCommand(["key", "value"]).exec(client); | ||
|
|
||
| expect(updatedSync).not.toEqual(initialSync); | ||
| }); | ||
|
|
||
| test("succesfully updates sync state with pipeline", async () => { | ||
| const initialSync = client.upstashSyncToken; | ||
|
|
||
| const { pipeline } = new Redis(client); | ||
| const p = pipeline(); | ||
|
|
||
| p.set("key1", "value1"); | ||
| p.set("key2", "value2"); | ||
| p.set("key3", "value3"); | ||
|
|
||
| await p.exec(); | ||
|
|
||
| const updatedSync = client.upstashSyncToken; | ||
|
|
||
| expect(initialSync).not.toEqual(updatedSync); | ||
| }); | ||
|
|
||
| test("updates after each element of promise.all", async () => { | ||
| let currentSync = client.upstashSyncToken; | ||
|
|
||
| const promises = Array.from({ length: 3 }, (_, i) => | ||
| new SetCommand([`key${i}`, `value${i}`]).exec(client).then(() => { | ||
| expect(client.upstashSyncToken).not.toEqual(currentSync); | ||
| currentSync = client.upstashSyncToken; | ||
| }), | ||
| ); | ||
|
|
||
| await Promise.all(promises); | ||
| }); | ||
|
|
||
| test("updates after successful lua script call", async () => { | ||
| const s = `redis.call('SET', 'mykey', 'myvalue') | ||
| return 1 | ||
| `; | ||
|
|
||
| const initialSync = client.upstashSyncToken; | ||
|
|
||
| const redis = new Redis(client); | ||
| const script = redis.createScript(s); | ||
|
|
||
| await script.exec([], []); | ||
|
|
||
| const updatedSync = client.upstashSyncToken; | ||
|
|
||
| expect(updatedSync).not.toEqual(initialSync); | ||
| }); | ||
|
|
||
| test("should not update the sync state in case of Redis client with manuel HTTP client and opt-out ryw", async () => { | ||
| const optOutClient = newHttpClient(); | ||
| const redis = new Redis(optOutClient, { readYourWrites: false }); | ||
|
|
||
| const initialSync = optOutClient.upstashSyncToken; | ||
|
|
||
| await redis.set("key", "value"); | ||
|
|
||
| const updatedSync = optOutClient.upstashSyncToken; | ||
|
|
||
| expect(updatedSync).toEqual(initialSync); | ||
| }); | ||
|
|
||
| test("should not update the sync state when public Redis interface is provided with opt-out", async () => { | ||
| const redis = new PublicRedis({ | ||
| url: process.env.UPSTASH_REDIS_REST_URL, | ||
| token: process.env.UPSTASH_REDIS_REST_TOKEN, | ||
| readYourWrites: false, | ||
| }); | ||
|
|
||
| // @ts-expect-error - We need the sync token for this test, which resides on the client | ||
| const initialSync = redis.client.upstashSyncToken; | ||
|
|
||
| await redis.set("key", "value"); | ||
|
|
||
| // @ts-expect-error - We need the sync token for this test, which resides on the client | ||
| const updatedSync = redis.client.upstashSyncToken; | ||
|
|
||
| expect(updatedSync).toEqual(initialSync); | ||
| }); | ||
|
|
||
| test("should update the sync state when public Redis interface is provided with default behaviour", async () => { | ||
| const redis = new PublicRedis({ | ||
| url: process.env.UPSTASH_REDIS_REST_URL, | ||
| token: process.env.UPSTASH_REDIS_REST_TOKEN, | ||
| }); | ||
|
|
||
| // @ts-expect-error - We need the sync token for this test, which resides on the client | ||
| const initialSync = redis.client.upstashSyncToken; | ||
|
|
||
| await redis.set("key", "value"); | ||
|
|
||
| // @ts-expect-error - We need the sync token for this test, which resides on the client | ||
| const updatedSync = redis.client.upstashSyncToken; | ||
| expect(updatedSync).not.toEqual(initialSync); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.