-
Notifications
You must be signed in to change notification settings - Fork 0
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
Python: add RANDOMKEY command #396
Changes from all commits
5f97080
67869a4
0991f08
a64c03b
13a087c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6487,6 +6487,47 @@ async def test_lolwut(self, redis_client: TGlideClient): | |||||
result = await redis_client.lolwut(2, [10, 20], RandomNode()) | ||||||
assert "Redis ver. " in node_result | ||||||
|
||||||
@pytest.mark.parametrize("cluster_mode", [True]) | ||||||
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) | ||||||
async def test_cluster_client_random_key(self, redis_client: TGlideClient): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And you can remove assert for client type then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will address all of these when I push to upstream |
||||||
key = get_random_string(10) | ||||||
|
||||||
# setup: delete all keys | ||||||
assert isinstance(redis_client, GlideClusterClient) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
assert await redis_client.flushall(FlushMode.SYNC) | ||||||
|
||||||
# no keys exists, so random_key returns None | ||||||
assert await redis_client.random_key() is None | ||||||
|
||||||
assert await redis_client.set(key, "foo") == OK | ||||||
# `key` should be the only existing key, so random_key should return `key` | ||||||
assert await redis_client.random_key() == key | ||||||
assert await redis_client.random_key(AllPrimaries()) == key | ||||||
|
||||||
@pytest.mark.parametrize("cluster_mode", [False]) | ||||||
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) | ||||||
async def test_standalone_client_random_key(self, redis_client: TGlideClient): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same in this test |
||||||
key = get_random_string(10) | ||||||
|
||||||
assert isinstance(redis_client, GlideClient) | ||||||
# setup: delete all keys in DB 0 and DB 1 | ||||||
assert await redis_client.select(0) == OK | ||||||
assert await redis_client.flushdb(FlushMode.SYNC) == OK | ||||||
assert await redis_client.select(1) == OK | ||||||
assert await redis_client.flushdb(FlushMode.SYNC) == OK | ||||||
|
||||||
# no keys exist so random_key returns None | ||||||
assert await redis_client.random_key() is None | ||||||
# set `key` in DB 1 | ||||||
assert await redis_client.set(key, "foo") == OK | ||||||
# `key` should be the only key in the database | ||||||
assert await redis_client.random_key() == key | ||||||
|
||||||
# switch back to DB 0 | ||||||
assert await redis_client.select(0) == OK | ||||||
# DB 0 should still have no keys, so random_key should still return None | ||||||
assert await redis_client.random_key() is None | ||||||
|
||||||
|
||||||
class TestMultiKeyCommandCrossSlot: | ||||||
@pytest.mark.parametrize("cluster_mode", [True]) | ||||||
|
+1 −1 | .github/workflows/rust.yml | |
+33 −0 | Cargo.lock | |
+1 −1 | Makefile | |
+4 −0 | redis/Cargo.toml | |
+16 −5 | redis/src/cluster.rs | |
+1 −1 | redis/src/cluster_async/connections_container.rs | |
+397 −104 | redis/src/cluster_async/mod.rs | |
+3 −3 | redis/src/cluster_routing.rs | |
+72 −2 | redis/src/cluster_slotmap.rs | |
+709 −0 | redis/src/commands/cluster_scan.rs | |
+9 −0 | redis/src/commands/mod.rs | |
+6 −0 | redis/src/lib.rs | |
+5 −0 | redis/src/types.rs | |
+320 −0 | redis/tests/support/cluster.rs | |
+38 −28 | redis/tests/support/mock_cluster.rs | |
+2 −2 | redis/tests/support/mod.rs | |
+329 −57 | redis/tests/test_cluster_async.rs | |
+825 −0 | redis/tests/test_cluster_scan.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was renamed in redis-rs, so I had to rename here to get the Rust code to build successfully