Skip to content

Commit

Permalink
test hsetnx
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Dec 13, 2024
1 parent 6f754fd commit bc93c19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,19 @@ def test_hset(self, cache: ValkeyCache):
assert cache.hexists("foo_hash1", "foo1")
assert cache.hexists("foo_hash1", "foo2")

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

res = cache.hsetnx("bar_hash1", "foo1", "baz1")
assert res == 1
result = cache.hget("bar_hash1", "foo1")
assert result == "baz1"
res = cache.hsetnx("bar_hash1", "foo1", "baz2")
assert res == 0
result = cache.hget("bar_hash1", "foo1")
assert result == "baz1"

def test_hdel(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip("ShardClient doesn't support get_client")
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 @@ -852,6 +852,16 @@ async def test_hset(self, cache: AsyncValkeyCache):
assert await cache.ahexists("foo_hash1", "foo1")
assert await cache.ahexists("foo_hash1", "foo2")

async def test_hsetnx(self, cache: AsyncValkeyCache):
res = await cache.ahsetnx("bar_hash1", "foo1", "baz1")
assert res == 1
result = await cache.ahget("bar_hash1", "foo1")
assert result == "baz1"
res = await cache.ahsetnx("bar_hash1", "foo1", "baz2")
assert res == 0
result = await cache.ahget("bar_hash1", "foo1")
assert result == "baz1"

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

0 comments on commit bc93c19

Please sign in to comment.