forked from valkey-io/valkey-glide
-
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
Merged
aaron-congo
merged 5 commits into
python/integ_acongo_randomkey
from
python/dev_acongo_randomkey
Jun 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f97080
Python: add RANDOMKEY command
aaron-congo 67869a4
Update redis-rs submodule and IT test
aaron-congo 0991f08
Rename response policy arm to match name change in redis-rs
aaron-congo a64c03b
PR suggestions
aaron-congo 13a087c
PR suggestions
aaron-congo 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 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 | ||
---|---|---|---|---|
|
@@ -6487,24 +6487,45 @@ 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, False]) | ||||
@pytest.mark.parametrize("cluster_mode", [True]) | ||||
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) | ||||
async def test_random_key(self, redis_client: TGlideClient): | ||||
async def test_cluster_client_random_key(self, redis_client: TGlideClient): | ||||
key = get_random_string(10) | ||||
|
||||
# set a key in the database in case it was empty | ||||
# 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 | ||||
|
||||
result = await redis_client.random_key() | ||||
assert result is not None | ||||
assert await redis_client.exists([result]) == 1 | ||||
@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) | ||||
|
||||
if isinstance(redis_client, GlideClusterClient): | ||||
result = await redis_client.random_key(AllPrimaries()) | ||||
assert result is not None | ||||
assert await redis_client.exists([result]) == 1 | ||||
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 | ||||
|
||||
assert await redis_client.flushall(FlushMode.SYNC) | ||||
# 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 | ||||
|
||||
|
||||
|
Oops, something went wrong.
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.
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.
And you can remove assert for client type then
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.
Good point, will address all of these when I push to upstream