Skip to content

Commit

Permalink
test scan
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Dec 21, 2024
1 parent 87d4a25 commit 2648a46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,25 @@ def test_iter_keys_generator(self, cache: ValkeyCache):
next_value = next(result)
assert next_value is not None

def test_scan(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip("ShardClient doesn't support scan")

cache.set("foo", "bar")
cursor, result = cache.scan()
assert result == ["foo"]
assert cursor == 0

def test_scan_with_match(self, cache: ValkeyCache):
if cache.client._has_compression_enabled():
pytest.skip("Compression is enabled, scan match is not supported")
if isinstance(cache.client, ShardClient):
pytest.skip("ShardClient doesn't support scan")

cache.set("foo", "bar")
_, result = cache.scan(match="f*")
assert result == ["foo"]

def test_primary_replica_switching(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip("ShardClient doesn't support get_client")
Expand Down
14 changes: 14 additions & 0 deletions tests/tests_async/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,20 @@ async def test_primary_replica_switching(self, cache: AsyncValkeyCache):
assert await client.get_client(write=True) == "Foo"
assert await client.get_client(write=False) == "Bar"

async def test_scan(self, cache: AsyncValkeyCache):
await cache.aset("foo", "bar")
cursor, result = await cache.ascan()
assert result == ["foo"]
assert cursor == 0

async def test_scan_with_match(self, cache: AsyncValkeyCache):
if cache.client._has_compression_enabled():
pytest.skip("Compression is enabled, scan match is not supported")

await cache.aset("foo", "bar")
_, result = await cache.ascan(match="f*")
assert result == ["foo"]

async def test_primary_replica_switching_with_index(self, cache: AsyncValkeyCache):
# if isinstance(cache.client, ShardClient):
# pytest.skip("ShardClient doesn't support get_client")
Expand Down

0 comments on commit 2648a46

Please sign in to comment.