Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-congo committed Jun 27, 2024
1 parent a64c03b commit 13a087c
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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):
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


Expand Down

0 comments on commit 13a087c

Please sign in to comment.