From 66a3bc91686452a9945ed20a340047e8cd7bccdb Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:39:11 +0300 Subject: [PATCH] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- glide-core/src/client/value_conversion.rs | 9 +++++++++ python/python/glide/async_commands/core.py | 8 ++++---- python/python/glide/async_commands/transaction.py | 6 +++--- python/python/tests/test_async_client.py | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/glide-core/src/client/value_conversion.rs b/glide-core/src/client/value_conversion.rs index 6dd470dc58..f903187273 100644 --- a/glide-core/src/client/value_conversion.rs +++ b/glide-core/src/client/value_conversion.rs @@ -486,4 +486,13 @@ mod tests { ) .is_err()); } + + #[test] + fn test_convert_spop_to_set_for_spop_count() { + assert!(matches!( + expected_type_for_cmd(redis::cmd("SPOP").arg("key1").arg("3")), + Some(ExpectedReturnType::Set) + )); + assert!(expected_type_for_cmd(redis::cmd("SPOP").arg("key1")).is_none()); + } } diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index fb2897d4ee..ca0844cb41 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1050,7 +1050,7 @@ async def scard(self, key: str) -> int: async def spop(self, key: str) -> str: """ Removes and returns one random member from the set stored at `key`. - + See https://valkey-io.github.io/commands/spop/ for more details. To pop multiple members, see `spop_count` @@ -1071,7 +1071,7 @@ async def spop(self, key: str) -> str: async def spop_count(self, key: str, count: int) -> Set[str]: """ Removes and returns up to `count` random members from the set stored at `key`, depending on the set's length. - + See https://valkey-io.github.io/commands/spop/ for details. To pop a single member, see `spop` @@ -1084,8 +1084,8 @@ async def spop_count(self, key: str, count: int) -> Set[str]: If `key` does not exist, empty set will be returned. Examples: - >>> await client.spop_count("my_list", 2) - {"value1", "value2"} + >>> await client.spop_count("my_set", 2) + {"value1", "value2"} # Removes and returns 2 random members from the set "my_set". >>> await client.spop_count("non_exiting_key", 2) Set() diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 444fbc4515..84e4237672 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -801,7 +801,7 @@ def spop(self: TTransaction, key: str) -> TTransaction: def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: """ - Removes and returns one random member from the set value store at `key`. + Removes and returns up to `count` random members from the set stored at `key`, depending on the set's length. See https://valkey-io.github.io/commands/spop/ for details. To pop a single member, see `spop` @@ -810,8 +810,8 @@ def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: count (int): The count of the elements to pop from the set. Commands response: - list: A set of popped elements will be returned depending on the set's length. - If `key` does not exist, empty list will be returned. + Set[str]: A set of popped elements will be returned depending on the set's length. + If `key` does not exist, empty set will be returned. """ return self.append_command(RequestType.Spop, [key, str(count)]) diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 2c599524d0..6e8dd74c58 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -936,6 +936,8 @@ async def test_spop(self, redis_client: TRedisClient): assert await redis_client.sadd(key, [member, member2, member3]) == 3 assert await redis_client.spop_count(key, 4) == {member, member2, member3} + assert await redis_client.scard(key) == 0 + assert await redis_client.spop("non_existing_key") == None assert await redis_client.spop_count("non_existing_key", 3) == set()