Skip to content

Commit

Permalink
Update python/python/glide/async_commands/core.py
Browse files Browse the repository at this point in the history
Co-authored-by: Shoham Elias <[email protected]>
  • Loading branch information
GilboaAWS and shohamazon committed Apr 11, 2024
1 parent 53adc7d commit 66a3bc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
8 changes: 4 additions & 4 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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)])
Expand Down
2 changes: 2 additions & 0 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 66a3bc9

Please sign in to comment.