Skip to content

Commit

Permalink
test hstrlen
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Dec 15, 2024
1 parent 263970c commit aa576d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from django_valkey.cache import ValkeyCache
from django_valkey.client import ShardClient, herd
from django_valkey.compressors.identity import IdentityCompressor
from django_valkey.serializers.json import JSONSerializer
from django_valkey.serializers.msgpack import MSGPackSerializer
from django_valkey.serializers.pickle import PickleSerializer
Expand Down Expand Up @@ -937,6 +938,17 @@ def test_hvals(self, cache: ValkeyCache):
result = cache.hvals("foo_hash6")
assert result == ["bar1", "bar2"]

def test_hstrlen(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip("ShardClient doesn't support get_client")
if not isinstance(cache.client._serializer, PickleSerializer):
pytest.skip("other serializers give different results")
if not isinstance(cache.client._compressor, IdentityCompressor):
pytest.skip("other compressors give different results")

cache.hset("hash7", "bar", "baz")
assert cache.hstrlen("hash7", "bar") == 18

def test_sadd(self, cache: ValkeyCache):
assert cache.sadd("foo", "bar") == 1
assert cache.smembers("foo") == {"bar"}
Expand Down
10 changes: 10 additions & 0 deletions tests/tests_async/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from django_valkey.async_cache.cache import AsyncValkeyCache
from django_valkey.async_cache.client import AsyncHerdClient
from django_valkey.compressors.identity import IdentityCompressor
from django_valkey.serializers.pickle import PickleSerializer
from django_valkey.serializers.json import JSONSerializer
from django_valkey.serializers.msgpack import MSGPackSerializer

Expand Down Expand Up @@ -946,6 +948,14 @@ async def test_hvals(self, cache: AsyncValkeyCache):
result = await cache.ahvals("foo_hash6")
assert result == ["bar1", "bar2"]

async def test_hstrlen(self, cache: AsyncValkeyCache):
if not isinstance(cache.client._serializer, PickleSerializer):
pytest.skip("other serializers give different results")
if not isinstance(cache.client._compressor, IdentityCompressor):
pytest.skip("other compressors give different results")
await cache.hset("hash7", "bar", "baz")
assert await cache.ahstrlen("hash7", "bar") == 18

async def test_sadd(self, cache: AsyncValkeyCache):
assert await cache.asadd("foo", "bar") == 1
assert await cache.asmembers("foo") == {"bar"}
Expand Down

0 comments on commit aa576d1

Please sign in to comment.