From 4c9e3463095c493f57c8c2d1eb832a85ebaa4034 Mon Sep 17 00:00:00 2001 From: GilboaAWS Date: Wed, 10 Apr 2024 12:14:15 +0000 Subject: [PATCH 01/22] Added SPOP command to python --- CHANGELOG.md | 2 +- glide-core/src/client/value_conversion.rs | 7 +++ python/python/glide/async_commands/core.py | 46 +++++++++++++++++++ .../glide/async_commands/transaction.py | 32 +++++++++++++ python/python/tests/test_async_client.py | 16 +++++++ python/python/tests/test_transaction.py | 6 +++ 6 files changed, 108 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75aa8272ef..bcbfd85566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ * Python: Added STRLEN command ([#1230](https://github.com/aws/glide-for-redis/pull/1230)) * Python: Added HKEYS command ([#1228](https://github.com/aws/glide-for-redis/pull/1228)) * Python: Added ZREMRANGEBYSCORE command ([#1151](https://github.com/aws/glide-for-redis/pull/1151)) -* Node: Added SPOP, SPOPCOUNT commands. ([#1117](https://github.com/aws/glide-for-redis/pull/1117)) +* Node, Python: Added SPOP, SPOPCOUNT commands. ([#1117](https://github.com/aws/glide-for-redis/pull/1117), [#1261](https://github.com/aws/glide-for-redis/pull/1261)) * Node: Added ZRANGE command ([#1115](https://github.com/aws/glide-for-redis/pull/1115)) * Python: Added RENAME command ([#1252](https://github.com/aws/glide-for-redis/pull/1252)) diff --git a/glide-core/src/client/value_conversion.rs b/glide-core/src/client/value_conversion.rs index 84a6626efa..6dd470dc58 100644 --- a/glide-core/src/client/value_conversion.rs +++ b/glide-core/src/client/value_conversion.rs @@ -233,6 +233,13 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option { b"ZRANK" | b"ZREVRANK" => cmd .position(b"WITHSCORE") .map(|_| ExpectedReturnType::ZrankReturnType), + b"SPOP" => { + if cmd.arg_idx(2).is_some() { + Some(ExpectedReturnType::Set) + } else { + None + } + } _ => None, } } diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 64d28fcb0c..9c9e93b83f 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1047,6 +1047,52 @@ async def scard(self, key: str) -> int: """ return cast(int, await self._execute_command(RequestType.SCard, [key])) + async def spop(self, key: str) -> str: + """ + Removes and returns one random member from the set value store at `key`. + See https://valkey-io.github.io/commands/spop/ for details. + To pop multiple members, see `spop_count` + + Args: + key (str): The key of the set. + + Returns: + str: The value of the popped member. + + Examples: + >>> await client.spop("my_list") + "value1" + >>> await client.spop("non_exiting_key") + None + + """ + return cast(str, await self._execute_command(RequestType.Spop, [key])) + + async def spop_count(self, key: str, count: int) -> Set[str]: + """ + Removes and returns one random member from the set value store at `key`. + See https://valkey-io.github.io/commands/spop/ for details. + To pop a single member, see `spop` + + Args: + key (str): The key of the set. + count (int): The count of the elements to pop from the set. + + Returns: + 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. + + Examples: + >>> await client.spop_count("my_list", 2) + {"value1", "value2"} + >>> await client.spop_count("non_exiting_key", 2) + Set() + + """ + return cast( + Set[str], await self._execute_command(RequestType.Spop, [key, str(count)]) + ) + async def sismember( self, key: str, diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index ea1da438db..444fbc4515 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -784,6 +784,38 @@ def scard(self: TTransaction, key: str) -> TTransaction: """ return self.append_command(RequestType.SCard, [key]) + def spop(self: TTransaction, key: str) -> TTransaction: + """ + Removes and returns one random member from the set value store at `key`. + See https://valkey-io.github.io/commands/spop/ for details. + To pop multiple members, see `spop_count` + + Args: + key (str): The key of the set. + + Commands response: + str: The value of the popped member. + + """ + return self.append_command(RequestType.Spop, [key]) + + def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: + """ + Removes and returns one random member from the set value store at `key`. + See https://valkey-io.github.io/commands/spop/ for details. + To pop a single member, see `spop` + + Args: + key (str): The key of the set. + 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. + + """ + return self.append_command(RequestType.Spop, [key, str(count)]) + def sismember( self: TTransaction, key: str, diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 3ab9a00d86..2c599524d0 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -923,6 +923,22 @@ async def test_sismember(self, redis_client: TRedisClient): assert not await redis_client.sismember(key, get_random_string(5)) assert not await redis_client.sismember("non_existing_key", member) + @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) + async def test_spop(self, redis_client: TRedisClient): + key = get_random_string(10) + member = get_random_string(5) + assert await redis_client.sadd(key, [member]) == 1 + assert await redis_client.spop(key) == member + + member2 = get_random_string(5) + member3 = get_random_string(5) + 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.spop("non_existing_key") == None + assert await redis_client.spop_count("non_existing_key", 3) == set() + @pytest.mark.parametrize("cluster_mode", [True, False]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_ltrim(self, redis_client: TRedisClient): diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 84b01639bc..a4c86bbd88 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -156,6 +156,12 @@ async def transaction_test( args.append(1) transaction.sismember(key7, "bar") args.append(True) + transaction.spop(key7) + args.append("bar") + transaction.sadd(key7, ["foo", "bar"]) + args.append(2) + transaction.spop_count(key7, 4) + args.append({"foo", "bar"}) transaction.zadd(key8, {"one": 1, "two": 2, "three": 3, "four": 4}) args.append(4) From a6b8fdf791e57d85ee89403b596ff0b1f53b8f7f Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:37:03 +0300 Subject: [PATCH 02/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 9c9e93b83f..02d4323324 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1049,8 +1049,9 @@ async def scard(self, key: str) -> int: async def spop(self, key: str) -> str: """ - Removes and returns one random member from the set value store at `key`. - See https://valkey-io.github.io/commands/spop/ for details. + 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` Args: From e4c1c6645cde84ee22c98adc015e31698a11ef78 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:37:17 +0300 Subject: [PATCH 03/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 02d4323324..78ce9620a6 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1061,7 +1061,7 @@ async def spop(self, key: str) -> str: str: The value of the popped member. Examples: - >>> await client.spop("my_list") + >>> await client.spop("my_set") "value1" >>> await client.spop("non_exiting_key") None From af7d82a8026decd8a94e4a4959266cb1f5f1a981 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:37:32 +0300 Subject: [PATCH 04/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 78ce9620a6..face43e22f 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1062,7 +1062,7 @@ async def spop(self, key: str) -> str: Examples: >>> await client.spop("my_set") - "value1" + "value1" # Removes and returns a random member from the set "my_set". >>> await client.spop("non_exiting_key") None From c7106ffbe4697f6bf1630ba86e0e48c1137f5bd2 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:37:40 +0300 Subject: [PATCH 05/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index face43e22f..7b61f44e01 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1065,7 +1065,6 @@ async def spop(self, key: str) -> str: "value1" # Removes and returns a random member from the set "my_set". >>> await client.spop("non_exiting_key") None - """ return cast(str, await self._execute_command(RequestType.Spop, [key])) From 7467cce65b793f691e2f05b415a63799b4b0bc95 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:38:33 +0300 Subject: [PATCH 06/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 7b61f44e01..8f10dfb169 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1070,7 +1070,8 @@ async def spop(self, key: str) -> str: async def spop_count(self, key: str, count: int) -> Set[str]: """ - 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` From 53adc7d90eaeced7a4335edd06bb1bf779fbc4a0 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:38:56 +0300 Subject: [PATCH 07/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 8f10dfb169..fb2897d4ee 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1080,8 +1080,8 @@ async def spop_count(self, key: str, count: int) -> Set[str]: count (int): The count of the elements to pop from the set. Returns: - 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. Examples: >>> await client.spop_count("my_list", 2) 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 08/22] 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() From 8c52b5ef830d0939482a2626f5a266a282154fe4 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:10:08 +0300 Subject: [PATCH 09/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index ca0844cb41..6ceb99e871 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1052,7 +1052,7 @@ 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` + To pop multiple members, see `spop_count`. Args: key (str): The key of the set. From 5462669ad4a0dae1f2e1d8ac825c0380c16e0f8d Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:10:41 +0300 Subject: [PATCH 10/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 6ceb99e871..76e897311a 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1088,7 +1088,6 @@ async def spop_count(self, key: str, count: int) -> Set[str]: {"value1", "value2"} # Removes and returns 2 random members from the set "my_set". >>> await client.spop_count("non_exiting_key", 2) Set() - """ return cast( Set[str], await self._execute_command(RequestType.Spop, [key, str(count)]) From f8d60465f529f3577c95fbf05db9768ddc6c462f Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:10:49 +0300 Subject: [PATCH 11/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 84e4237672..dc139d893a 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -787,6 +787,7 @@ def scard(self: TTransaction, key: str) -> TTransaction: def spop(self: TTransaction, key: str) -> TTransaction: """ Removes and returns one random member from the set value store at `key`. + See https://valkey-io.github.io/commands/spop/ for details. To pop multiple members, see `spop_count` From 581baca0a9c23534a5cefe6892ca668bbc368b15 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:11:01 +0300 Subject: [PATCH 12/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index dc139d893a..910918a320 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -796,7 +796,6 @@ def spop(self: TTransaction, key: str) -> TTransaction: Commands response: str: The value of the popped member. - """ return self.append_command(RequestType.Spop, [key]) From ca4907f20423b77fa9a8e70333b3bfb52b24425d Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:11:38 +0300 Subject: [PATCH 13/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 910918a320..afb479d504 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -802,6 +802,7 @@ def spop(self: TTransaction, key: str) -> TTransaction: def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: """ 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` From 93b7763e267990787b818ff9281dfac16a47cfc1 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:11:49 +0300 Subject: [PATCH 14/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 76e897311a..6f26039f4f 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1073,7 +1073,7 @@ 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` + To pop a single member, see `spop`. Args: key (str): The key of the set. From d55c5f8f83d89b737e55807431feee4f4e7cbdc1 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:12:01 +0300 Subject: [PATCH 15/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index afb479d504..6c0b2d902e 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -804,7 +804,7 @@ def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: 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` + To pop a single member, see `spop`. Args: key (str): The key of the set. From 820c3c56990b6b294ca593ad8b1febef96bccd01 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:12:14 +0300 Subject: [PATCH 16/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 6c0b2d902e..b1bab0298e 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -812,7 +812,7 @@ def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: Commands response: 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. + If `key` does not exist, an empty set will be returned. """ return self.append_command(RequestType.Spop, [key, str(count)]) From 75481c60f49db3f3bf8972efd82e5f726b792888 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:12:24 +0300 Subject: [PATCH 17/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index b1bab0298e..58cec2fa05 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -813,7 +813,6 @@ def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: Commands response: Set[str]: A set of popped elements will be returned depending on the set's length. If `key` does not exist, an empty set will be returned. - """ return self.append_command(RequestType.Spop, [key, str(count)]) From dd953b0c413848dd41353833f9e2886f4abbbc18 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:12:35 +0300 Subject: [PATCH 18/22] Update python/python/glide/async_commands/transaction.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/transaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 58cec2fa05..e5c8bc2aed 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -789,7 +789,7 @@ def spop(self: TTransaction, key: str) -> TTransaction: Removes and returns one random member from the set value store at `key`. See https://valkey-io.github.io/commands/spop/ for details. - To pop multiple members, see `spop_count` + To pop multiple members, see `spop_count`. Args: key (str): The key of the set. From af1a86a7314703a4210e598f324cd8360543c6e2 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:12:53 +0300 Subject: [PATCH 19/22] Update python/python/glide/async_commands/core.py Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 6f26039f4f..cf5e6cf9fd 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1081,7 +1081,7 @@ async def spop_count(self, key: str, count: int) -> Set[str]: Returns: 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. + If `key` does not exist, an empty set will be returned. Examples: >>> await client.spop_count("my_set", 2) From 28af9467e387e8db5d0fda350741f0b14a41c5dc Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Thu, 11 Apr 2024 13:26:14 +0000 Subject: [PATCH 20/22] fix black errors --- python/python/glide/async_commands/transaction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index e5c8bc2aed..538082fdd6 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -787,7 +787,7 @@ def scard(self: TTransaction, key: str) -> TTransaction: def spop(self: TTransaction, key: str) -> TTransaction: """ Removes and returns one random member from the set value store at `key`. - + See https://valkey-io.github.io/commands/spop/ for details. To pop multiple members, see `spop_count`. @@ -802,7 +802,7 @@ def spop(self: TTransaction, key: str) -> TTransaction: def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: """ 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`. From 1e95bd41fa7fee16b9f024d597764cae6785ba58 Mon Sep 17 00:00:00 2001 From: Gilboab <97948000+GilboaAWS@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:02:04 +0300 Subject: [PATCH 21/22] Apply suggestions from code review Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com> --- python/python/glide/async_commands/core.py | 7 ++++--- python/python/glide/async_commands/transaction.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index cf5e6cf9fd..08a57a0419 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1047,7 +1047,7 @@ async def scard(self, key: str) -> int: """ return cast(int, await self._execute_command(RequestType.SCard, [key])) - async def spop(self, key: str) -> str: + async def spop(self, key: str) -> Optional[str]: """ Removes and returns one random member from the set stored at `key`. @@ -1058,7 +1058,8 @@ async def spop(self, key: str) -> str: key (str): The key of the set. Returns: - str: The value of the popped member. + Optional[str]: The value of the popped member. + If `key` does not exist, None will be returned. Examples: >>> await client.spop("my_set") @@ -1066,7 +1067,7 @@ async def spop(self, key: str) -> str: >>> await client.spop("non_exiting_key") None """ - return cast(str, await self._execute_command(RequestType.Spop, [key])) + return cast(Optional[str], await self._execute_command(RequestType.Spop, [key])) async def spop_count(self, key: str, count: int) -> Set[str]: """ diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 538082fdd6..091a52ee1f 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -786,7 +786,7 @@ def scard(self: TTransaction, key: str) -> TTransaction: def spop(self: TTransaction, key: str) -> TTransaction: """ - Removes and returns one random member from the set value store at `key`. + Removes and returns one random member from the set stored at `key`. See https://valkey-io.github.io/commands/spop/ for details. To pop multiple members, see `spop_count`. @@ -795,7 +795,8 @@ def spop(self: TTransaction, key: str) -> TTransaction: key (str): The key of the set. Commands response: - str: The value of the popped member. + Optional[str]: The value of the popped member. + If `key` does not exist, None will be returned. """ return self.append_command(RequestType.Spop, [key]) From 30c78d74b49ea99d58f22517e571d58a8d01a7ae Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:01:19 +0300 Subject: [PATCH 22/22] Apply suggestions from code review --- python/python/glide/async_commands/core.py | 2 +- python/python/glide/async_commands/transaction.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 08a57a0419..e52ba63b9f 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1073,7 +1073,7 @@ 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. + See https://valkey-io.github.io/commands/spop/ for more details. To pop a single member, see `spop`. Args: diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 091a52ee1f..acbf2048f8 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -788,7 +788,7 @@ def spop(self: TTransaction, key: str) -> TTransaction: """ Removes and returns one random member from the set stored at `key`. - See https://valkey-io.github.io/commands/spop/ for details. + See https://valkey-io.github.io/commands/spop/ for more details. To pop multiple members, see `spop_count`. Args: @@ -804,7 +804,7 @@ def spop_count(self: TTransaction, key: str, count: int) -> TTransaction: """ 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. + See https://valkey-io.github.io/commands/spop/ for more details. To pop a single member, see `spop`. Args: