Skip to content

Commit

Permalink
Fixed tests and addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GumpacG committed Jul 1, 2024
1 parent 0f43665 commit d47eb43
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
6 changes: 3 additions & 3 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5473,7 +5473,7 @@ async def zscan(
`String` pairs, where the value is at even indices and the score is at odd indices.
Examples:
# Assume "key" contains a sorted set with 200 members
# Assume "key" contains a sorted set with multiple members
>>> result_cursor = "0"
>>> while True:
... result = await redis_client.zscan("key", "0", match="*", count=5)
Expand Down Expand Up @@ -5509,7 +5509,7 @@ async def hscan(
count: Optional[int] = None,
) -> List[Union[str, List[str]]]:
"""
Iterates incrementally over a sorted set.
Iterates incrementally over a hash.
See https://valkey.io/commands/hscan for more details.
Expand All @@ -5534,7 +5534,7 @@ async def hscan(
where the value is at even indices and the score is at odd indices.
Examples:
# Assume "key" contains a sorted set with 200 members
# Assume "key" contains a hash with multiple members
>>> result_cursor = "0"
>>> while True:
... result = await redis_client.hscan("key", "0", match="*", count=3)
Expand Down
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 @@ -3997,7 +3997,7 @@ def hscan(
count: Optional[int] = None,
) -> TTransaction:
"""
Iterates incrementally over a sorted set.
Iterates incrementally over a hash.
See https://valkey.io/commands/hscan for more details.
Expand Down
55 changes: 37 additions & 18 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7970,16 +7970,14 @@ async def test_zscan(self, redis_client: GlideClusterClient):
num_map_with_str_scores = {}
for i in range(50000): # Use large dataset to force an iterative cursor.
num_map.update({"value " + str(i): i})
num_map_with_str_scores.update(
{b"value " + str(i).encode(): str(i).encode()}
)
num_map_with_str_scores.update({"value " + str(i): str(i)})
char_map = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4}
char_map_with_str_scores = {
b"a": b"0",
b"b": b"1",
b"c": b"2",
b"d": b"3",
b"e": b"4",
"a": "0",
"b": "1",
"c": "2",
"d": "3",
"e": "4",
}

convert_list_to_dict = lambda list: {
Expand All @@ -8002,7 +8000,9 @@ async def test_zscan(self, redis_client: GlideClusterClient):
result_collection = result[result_collection_index]
assert result[result_cursor_index] == initial_cursor.encode()
assert len(result_collection) == len(char_map) * 2
assert convert_list_to_dict(result_collection) == char_map_with_str_scores
assert convert_list_to_dict(result_collection) == cast(
list, convert_string_to_bytes_object(char_map_with_str_scores)
)

result = await redis_client.zscan(key1, initial_cursor, match="a")
result_collection = result[result_collection_index]
Expand All @@ -8012,16 +8012,26 @@ async def test_zscan(self, redis_client: GlideClusterClient):
# Result contains a subset of the key
assert await redis_client.zadd(key1, num_map) == len(num_map)
full_result_map = {}
result = await redis_client.zscan(key1, initial_cursor)
result_cursor = result[result_cursor_index]
result = result = cast(
list,
convert_bytes_to_string_object(
await redis_client.zscan(key1, initial_cursor)
),
)
result_cursor = str(result[result_cursor_index])
result_iteration_collection: dict[str, str] = convert_list_to_dict(
result[result_collection_index]
)
full_result_map.update(result_iteration_collection)

# 0 is returned for the cursor of the last iteration.
while result_cursor != b"0":
next_result = await redis_client.zscan(key1, result_cursor.decode("utf-8"))
while result_cursor != "0":
next_result = cast(
list,
convert_bytes_to_string_object(
await redis_client.zscan(key1, result_cursor)
),
)
next_result_cursor = next_result[result_cursor_index]
assert next_result_cursor != result_cursor

Expand Down Expand Up @@ -8113,18 +8123,27 @@ async def test_hscan(self, redis_client: GlideClusterClient):

# Result contains a subset of the key
assert await redis_client.hset(key1, num_map) == len(num_map)
result_cursor = "0"
full_result_map = {}
result = await redis_client.hscan(key1, result_cursor)
result_cursor = result[result_cursor_index]
result = result = cast(
list,
convert_bytes_to_string_object(
await redis_client.hscan(key1, initial_cursor)
),
)
result_cursor = str(result[result_cursor_index])
result_iteration_collection: dict[str, str] = convert_list_to_dict(
result[result_collection_index]
)
full_result_map.update(result_iteration_collection)

# 0 is returned for the cursor of the last iteration.
while result_cursor != b"0":
next_result = await redis_client.hscan(key1, result_cursor.decode("utf-8"))
while result_cursor != "0":
next_result = cast(
list,
convert_bytes_to_string_object(
await redis_client.hscan(key1, result_cursor)
),
)
next_result_cursor = next_result[result_cursor_index]
assert next_result_cursor != result_cursor

Expand Down
2 changes: 1 addition & 1 deletion python/python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def transaction_test(
transaction.hscan(key4, "0")
args.append([b"0", [key3.encode(), b"10.5"]])
transaction.hscan(key4, "0", match="*", count=10)
args.append([b"0", [key3, b"10.5"]])
args.append([b"0", [key3.encode(), b"10.5"]])
transaction.hrandfield(key4)
args.append(key3_bytes)
transaction.hrandfield_count(key4, 1)
Expand Down

0 comments on commit d47eb43

Please sign in to comment.