From 2648a4678c4cd5b94ac6f8be06b44aceba00c038 Mon Sep 17 00:00:00 2001 From: amirreza Date: Sat, 21 Dec 2024 13:55:32 +0330 Subject: [PATCH] test scan --- tests/test_backend.py | 19 +++++++++++++++++++ tests/tests_async/test_backend.py | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_backend.py b/tests/test_backend.py index 7ac99da..be46b66 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -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") diff --git a/tests/tests_async/test_backend.py b/tests/tests_async/test_backend.py index 82400ad..da62f3a 100644 --- a/tests/tests_async/test_backend.py +++ b/tests/tests_async/test_backend.py @@ -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")