-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from upstash/dx-1019-redis-sdks-read-your-writ…
…es-support DX-1019: Read Your Writes
- Loading branch information
Showing
12 changed files
with
335 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,141 @@ | ||
import pytest | ||
|
||
from upstash_redis import AsyncRedis, Redis | ||
|
||
|
||
@pytest.mark.parametrize("redis", [{"read_your_writes": True}], indirect=True) | ||
def test_should_update_sync_token_on_basic_request(redis: Redis): | ||
initial_token = redis._sync_token | ||
redis.set("key", "value") | ||
updated_token = redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("async_redis", [{"read_your_writes": True}], indirect=True) | ||
@pytest.mark.asyncio | ||
async def test_should_update_sync_token_on_basic_request_async(async_redis: AsyncRedis): | ||
initial_token = async_redis._sync_token | ||
await async_redis.set("key", "value") | ||
updated_token = async_redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("redis", [{"read_your_writes": True}], indirect=True) | ||
def test_should_update_sync_token_on_pipeline(redis: Redis): | ||
initial_token = redis._sync_token | ||
|
||
pipeline = redis.pipeline() | ||
pipeline.set("key", "value") | ||
pipeline.set("key2", "value2") | ||
pipeline.exec() | ||
|
||
updated_token = redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("async_redis", [{"read_your_writes": True}], indirect=True) | ||
@pytest.mark.asyncio() | ||
async def test_should_update_sync_token_on_pipeline_async(async_redis: AsyncRedis): | ||
initial_token = async_redis._sync_token | ||
|
||
pipeline = async_redis.pipeline() | ||
pipeline.set("key", "value") | ||
pipeline.set("key2", "value2") | ||
await pipeline.exec() | ||
|
||
updated_token = async_redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("redis", [{"read_your_writes": True}], indirect=True) | ||
def test_should_update_sync_token_on_multiexec(redis: Redis): | ||
initial_token = redis._sync_token | ||
|
||
multi = redis.multi() | ||
multi.set("key", "value") | ||
multi.set("key2", "value2") | ||
multi.exec() | ||
|
||
updated_token = redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("async_redis", [{"read_your_writes": True}], indirect=True) | ||
@pytest.mark.asyncio | ||
async def test_should_update_sync_token_on_multiexec_async(async_redis: AsyncRedis): | ||
initial_token = async_redis._sync_token | ||
|
||
multi = async_redis.multi() | ||
multi.set("key", "value") | ||
multi.set("key2", "value2") | ||
await multi.exec() | ||
|
||
updated_token = async_redis._sync_token | ||
assert initial_token != updated_token | ||
|
||
|
||
@pytest.mark.parametrize("redis", [{"read_your_writes": True}], indirect=True) | ||
def test_updates_after_successful_lua_script_call(redis: Redis): | ||
initial_token = redis._sync_token | ||
|
||
redis.eval( | ||
""" | ||
redis.call('SET', 'mykey', 'myvalue') | ||
return 1 | ||
""" | ||
) | ||
|
||
updated_token = redis._sync_token | ||
assert updated_token != initial_token | ||
|
||
|
||
@pytest.mark.parametrize("async_redis", [{"read_your_writes": True}], indirect=True) | ||
@pytest.mark.asyncio | ||
async def test_updates_after_successful_lua_script_call_async(async_redis: AsyncRedis): | ||
initial_token = async_redis._sync_token | ||
|
||
await async_redis.eval( | ||
""" | ||
redis.call('SET', 'mykey', 'myvalue') | ||
return 1 | ||
""" | ||
) | ||
|
||
updated_token = async_redis._sync_token | ||
assert updated_token != initial_token | ||
|
||
|
||
@pytest.mark.parametrize("redis", [{"read_your_writes": False}], indirect=True) | ||
def test_should_not_update_sync_state_with_opt_out_ryw(redis: Redis): | ||
initial_token = redis._sync_token | ||
redis.set("key", "value") | ||
updated_token = redis._sync_token | ||
assert updated_token == initial_token | ||
|
||
|
||
@pytest.mark.parametrize("async_redis", [{"read_your_writes": False}], indirect=True) | ||
@pytest.mark.asyncio | ||
async def test_should_not_update_sync_state_with_opt_out_ryw_async( | ||
async_redis: AsyncRedis | ||
): | ||
initial_token = async_redis._sync_token | ||
await async_redis.set("key", "value") | ||
updated_token = async_redis._sync_token | ||
assert updated_token == initial_token | ||
|
||
|
||
def test_should_update_sync_state_with_default_behavior(redis: Redis): | ||
initial_token = redis._sync_token | ||
redis.set("key", "value") | ||
updated_token = redis._sync_token | ||
assert updated_token != initial_token | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_should_update_sync_state_with_default_behavior_async( | ||
async_redis: AsyncRedis | ||
): | ||
initial_token = async_redis._sync_token | ||
await async_redis.set("key", "value") | ||
updated_token = async_redis._sync_token | ||
assert updated_token != initial_token |
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
__version__ = "1.1.0" | ||
|
||
from upstash_redis.asyncio.client import Redis as AsyncRedis | ||
from upstash_redis.client import Redis | ||
|
||
__all__ = ["Redis"] | ||
__all__ = ["AsyncRedis", "Redis"] |
Oops, something went wrong.