Skip to content

Commit

Permalink
fixed typing
Browse files Browse the repository at this point in the history
  • Loading branch information
avifenesh committed Jun 28, 2024
1 parent 20aea16 commit dcd6da0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 57 deletions.
1 change: 0 additions & 1 deletion python/python/glide/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
float,
Set[T],
List[T],
List[Union[str, List[str]]],
]
TRequest = Union[RedisRequest, ConnectionRequest]
# When routing to a single node, response will be T
Expand Down
126 changes: 70 additions & 56 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6676,11 +6676,12 @@ async def test_simple_cluster_scan(self, redis_client: GlideClusterClient):
for key in expected_keys:
await redis_client.set(key, "value")
cursor = ClusterScanCursor(None)
keys = []
keys: list[str] = []
while not cursor.is_finished():
result = await redis_client.scan(cursor)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)

assert set(expected_keys) == set(keys)

Expand All @@ -6698,14 +6699,15 @@ async def test_cluster_scan_with_object_type_and_pattern(
unexpected_pattern_keys = [f"{i}" for i in range(200, 300)]
for key in unexpected_pattern_keys:
await redis_client.set(key, "value")
keys = []
keys: list[str] = []
cursor = ClusterScanCursor(None)
while not cursor.is_finished():
result = await redis_client.scan(
cursor, match="key:*", type=ObjectType.STRING
)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)

assert set(expected_keys) == set(keys)
assert not set(unexpected_type_keys).intersection(set(keys))
Expand All @@ -6718,20 +6720,20 @@ async def test_cluster_scan_with_count(self, redis_client: GlideClusterClient):
for key in expected_keys:
await redis_client.set(key, "value")
cursor = ClusterScanCursor(None)
keys = []
keys: list[str] = []
succefull_compared_scans = 0
while not cursor.is_finished():
result_of_1 = await redis_client.scan(cursor, count=1)
cursor = result_of_1[0]
keys_of_1 = result_of_1[1]
keys.extend(keys_of_1)
cursor = cast(ClusterScanCursor, result_of_1[0])
result_keys_of_1 = cast(list[str], result_of_1[1])
keys.extend(result_keys_of_1)
if cursor.is_finished():
break
result_of_100 = await redis_client.scan(cursor, count=100)
cursor = result_of_100[0]
keys_of_100 = result_of_100[1]
keys.extend(keys_of_100)
if keys_of_100 > keys_of_1:
cursor = cast(ClusterScanCursor, result_of_100[0])
result_keys_of_100 = cast(list[str], result_of_100[1])
keys.extend(result_keys_of_100)
if len(result_keys_of_100) > len(result_keys_of_1):
succefull_compared_scans += 1

assert set(expected_keys) == set(keys)
Expand All @@ -6747,11 +6749,12 @@ async def test_cluster_scan_with_match(self, redis_client: GlideClusterClient):
for key in expected_keys:
await redis_client.set(key, "value")
cursor = ClusterScanCursor(None)
keys = []
keys: list[str] = []
while not cursor.is_finished():
result = await redis_client.scan(cursor, match="key:*")
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)
assert set(expected_keys) == set(keys)
assert not set(unexpected_keys).intersection(set(keys))

Expand All @@ -6764,7 +6767,7 @@ async def test_cluster_scan_cleaning_cursor(self, redis_client: GlideClusterClie
await redis_client.set(key, "value")
cursor = ClusterScanCursor(None)
result = await redis_client.scan(cursor)
cursor = result[0]
cursor = cast(ClusterScanCursor, result[0])
cursor_string = str(cursor)
cursor.__del__()
new_cursor_with_same_id = ClusterScanCursor(cursor_string)
Expand Down Expand Up @@ -6797,47 +6800,51 @@ async def test_cluster_scan_all_types(self, redis_client: GlideClusterClient):
await redis_client.zadd(key, {"value": 1})

cursor = ClusterScanCursor(None)
keys = []
keys: list[str] = []
while not cursor.is_finished():
result = await redis_client.scan(cursor, type=ObjectType.STRING)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)
assert set(string_keys) == set(keys)
assert not set(set_keys).intersection(set(keys))
assert not set(hash_keys).intersection(set(keys))
assert not set(list_keys).intersection(set(keys))
assert not set(zset_keys).intersection(set(keys))

cursor = ClusterScanCursor(None)
keys = []
keys.clear()
while not cursor.is_finished():
result = await redis_client.scan(cursor, type=ObjectType.SET)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)
assert set(set_keys) == set(keys)
assert not set(string_keys).intersection(set(keys))
assert not set(hash_keys).intersection(set(keys))
assert not set(list_keys).intersection(set(keys))
assert not set(zset_keys).intersection(set(keys))

cursor = ClusterScanCursor(None)
keys = []
keys.clear()
while not cursor.is_finished():
result = await redis_client.scan(cursor, type=ObjectType.HASH)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)
assert set(hash_keys) == set(keys)
assert not set(string_keys).intersection(set(keys))
assert not set(set_keys).intersection(set(keys))
assert not set(list_keys).intersection(set(keys))
assert not set(zset_keys).intersection(set(keys))

cursor = ClusterScanCursor(None)
keys = []
keys.clear()
while not cursor.is_finished():
result = await redis_client.scan(cursor, type=ObjectType.LIST)
cursor = result[0]
keys.extend(result[1])
cursor = cast(ClusterScanCursor, result[0])
result_keys = cast(list[str], result[1])
keys.extend(result_keys)
assert set(list_keys) == set(keys)
assert not set(string_keys).intersection(set(keys))
assert not set(set_keys).intersection(set(keys))
Expand All @@ -6851,12 +6858,13 @@ async def test_simple_scan(self, redis_client: GlideClient):
expected_keys = [f"key:{i}" for i in range(100)]
for key in expected_keys:
await redis_client.set(key, "value")
keys = []
keys: list[str] = []
cursor = 0
while True:
result = await redis_client.scan(cursor)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(expected_keys) == set(keys)
Expand All @@ -6873,14 +6881,15 @@ async def test_scan_with_object_type_and_pattern(self, redis_client: GlideClient
unexpected_pattern_keys = [f"{i}" for i in range(200, 300)]
for key in unexpected_pattern_keys:
await redis_client.set(key, "value")
keys = []
keys: list[str] = []
cursor = 0
while True:
result = await redis_client.scan(
cursor, match="key:*", type=ObjectType.STRING
)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(expected_keys) == set(keys)
Expand All @@ -6894,16 +6903,16 @@ async def test_scan_with_count(self, redis_client: GlideClient):
for key in expected_keys:
await redis_client.set(key, "value")
cursor = 0
keys = []
keys: list[str] = []
succefull_compared_scans = 0
while True:
result_of_1 = await redis_client.scan(cursor, count=1)
cursor = result_of_1[0]
keys_of_1 = result_of_1[1]
cursor = cast(int, result_of_1[0])
keys_of_1 = cast(list[str], result_of_1[1])
keys.extend(keys_of_1)
result_of_100 = await redis_client.scan(cursor, count=100)
cursor = result_of_100[0]
keys_of_100 = result_of_100[1]
cursor = cast(int, result_of_100[0])
keys_of_100 = cast(list[str], result_of_100[1])
keys.extend(keys_of_100)
if keys_of_100 > keys_of_1:
succefull_compared_scans += 1
Expand All @@ -6922,11 +6931,12 @@ async def test_cluster_with_match(self, redis_client: GlideClient):
for key in expected_keys:
await redis_client.set(key, "value")
cursor = 0
keys = []
keys: list[str] = []
while True:
result = await redis_client.scan(cursor, match="key:*")
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(expected_keys) == set(keys)
Expand Down Expand Up @@ -6957,11 +6967,12 @@ async def test_scan_all_types(self, redis_client: GlideClient):
await redis_client.zadd(key, {"value": 1})

cursor = 0
keys = []
keys: list[str] = []
while True:
result = await redis_client.scan(cursor, type=ObjectType.STRING)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(string_keys) == set(keys)
Expand All @@ -6971,11 +6982,12 @@ async def test_scan_all_types(self, redis_client: GlideClient):
assert not set(zset_keys).intersection(set(keys))

cursor = 0
keys = []
keys.clear()
while True:
result = await redis_client.scan(cursor, type=ObjectType.SET)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(set_keys) == set(keys)
Expand All @@ -6985,11 +6997,12 @@ async def test_scan_all_types(self, redis_client: GlideClient):
assert not set(zset_keys).intersection(set(keys))

cursor = 0
keys = []
keys.clear()
while True:
result = await redis_client.scan(cursor, type=ObjectType.HASH)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(hash_keys) == set(keys)
Expand All @@ -6999,11 +7012,12 @@ async def test_scan_all_types(self, redis_client: GlideClient):
assert not set(zset_keys).intersection(set(keys))

cursor = 0
keys = []
keys.clear()
while True:
result = await redis_client.scan(cursor, type=ObjectType.LIST)
cursor = result[0]
keys.extend(result[1])
cursor = cast(int, result[0])
new_keys = cast(list[str], result[1])
keys.extend(new_keys)
if cursor == 0:
break
assert set(list_keys) == set(keys)
Expand Down

0 comments on commit dcd6da0

Please sign in to comment.