Skip to content

Commit

Permalink
fix route doc
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon committed Mar 20, 2024
1 parent 11a7b5a commit cd0ee03
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
7 changes: 4 additions & 3 deletions python/python/glide/async_commands/cluster_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,15 @@ async def dbsize(self, route: Optional[Route] = None) -> int:
See https://redis.io/commands/dbsize for more details.
Args:
route (Optional[Route]): The command will be routed to all nodes, unless `route` is provided,
route (Optional[Route]): The command will be routed to all primaries, unless `route` is provided,
in which case the client will route the command to the nodes defined by `route`.
Returns:
int: The number of keys in the currently selected database.
int: The number of keys in the database.
In the case of routing the query to multiple nodes, returns the aggregated number of keys across the different nodes.
Examples:
>>> await client.dbsize()
10 # Indicates there are 10 keys in the current database.
10 # Indicates there are 10 keys in the cluster.
"""
return cast(int, await self._execute_command(RequestType.DBSize, [], route))
2 changes: 1 addition & 1 deletion python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def dbsize(self: TTransaction) -> TTransaction:
See https://redis.io/commands/dbsize for more details.
Commands response:
int: The number of keys in the currently selected database.
int: The number of keys in the database.
"""
return self.append_command(RequestType.DBSize, [])

Expand Down
14 changes: 5 additions & 9 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,22 +1564,18 @@ async def test_echo(self, redis_client: TRedisClient):
async def test_dbsize(self, redis_client: TRedisClient):
assert await redis_client.custom_command(["FLUSHALL"]) == OK

key_value_pairs = [(get_random_string(10), "foo") for _ in range(10)]
assert await redis_client.dbsize() == 0
key_value_pairs = [(get_random_string(10), "foo") for _ in range(10)]

for key, value in key_value_pairs:
assert await redis_client.set(key, value) == OK
assert await redis_client.dbsize() == 10

if isinstance(redis_client, RedisClusterClient):
cluster_nodes = await redis_client.custom_command(["CLUSTER", "NODES"])
assert isinstance(cluster_nodes, (str, list))
cluster_nodes = get_first_result(cluster_nodes)
replica_count = cluster_nodes.count("slave")
master_count = cluster_nodes.count("master")
assert await redis_client.dbsize(AllNodes()) == 10 * (
replica_count / master_count + 1
)
assert await redis_client.custom_command(["FLUSHALL"]) == OK
key = get_random_string(5)
assert await redis_client.set(key, value) == OK
assert await redis_client.dbsize(SlotKeyRoute(SlotType.PRIMARY, key)) == 1
else:
assert await redis_client.select(1) == OK
assert await redis_client.dbsize() == 0
Expand Down

0 comments on commit cd0ee03

Please sign in to comment.