Skip to content

Commit d7d8d5a

Browse files
author
Joshua
committed
Add async tests for hsetex
Signed-off-by: Joshua <joshua.gehlen@fkie.fraunhofer.de>
1 parent e27fbbd commit d7d8d5a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tests/test_asyncio/test_commands.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,32 @@ async def test_hstrlen(self, r: valkey.Valkey):
21512151
assert await r.hstrlen("a", "1") == 2
21522152
assert await r.hstrlen("a", "2") == 3
21532153

2154+
@skip_if_server_version_lt("9.0.0")
2155+
async def test_hsetex(self, r):
2156+
assert await r.hsetex("a", "field1", "value1", ex=5) == 1
2157+
assert await r.hget("a", "field1") == b"value1"
2158+
assert await r.hsetex("a", "field1", "value2", ex=5) == 1
2159+
assert await r.hget("a", "field1") == b"value2"
2160+
2161+
@skip_if_server_version_lt("9.0.0")
2162+
async def test_hsetex_invalid_params(self, r):
2163+
with pytest.raises(exceptions.DataError):
2164+
await r.hsetex("a", "field1", "value1", ex=5, px=5000)
2165+
2166+
@skip_if_server_version_lt("9.0.0")
2167+
async def test_hsetex_px(self, r):
2168+
assert await r.hsetex("a", "field1", "value1", px=5000) == 1
2169+
assert await r.hget("a", "field1") == b"value1"
2170+
assert await r.hsetex("a", "field1", "value2", px=5000) == 1
2171+
assert await r.hget("a", "field1") == b"value2"
2172+
2173+
@skip_if_server_version_lt("9.0.0")
2174+
async def test_hsetex_mapping(self, r):
2175+
mapping = {"field1": "value1", "field2": "value2"}
2176+
assert await r.hsetex("a", mapping=mapping, ex=5) == 1
2177+
assert await r.hget("a", "field1") == b"value1"
2178+
assert await r.hget("a", "field2") == b"value2"
2179+
21542180
# SORT
21552181
async def test_sort_basic(self, r: valkey.Valkey):
21562182
await r.rpush("a", "3", "2", "1", "4")

tests/test_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3244,7 +3244,7 @@ def test_hsetex(self, r):
32443244
assert r.hget("a", "field1") == b"value2"
32453245

32463246
@skip_if_server_version_lt("9.0.0")
3247-
def test_hset_ex_invalid_params(self, r):
3247+
def test_hsetex_invalid_params(self, r):
32483248
with pytest.raises(exceptions.DataError):
32493249
r.hsetex("a", "field1", "value1", ex=5, px=5000) # Both ex and px provided
32503250

0 commit comments

Comments
 (0)