Skip to content

Commit 4ba9a0d

Browse files
committed
add tests for decr_version
1 parent 900a963 commit 4ba9a0d

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

tests/test_backend.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,28 @@ def test_ttl_incr_version_no_timeout(self, cache: ValkeyCache):
536536

537537
assert my_value == "hello world!"
538538

539+
def test_decr_version(self, cache: ValkeyCache):
540+
cache.set("keytest", 2, version=3)
541+
res = cache.get("keytest", version=3)
542+
assert res == 2
543+
544+
cache.decr_version("keytest", version=3)
545+
546+
res = cache.get("keytest", version=3)
547+
assert res is None
548+
549+
res = cache.get("keytest", version=2)
550+
assert res == 2
551+
552+
def test_ttl_decr_version_no_timeout(self, cache: ValkeyCache):
553+
cache.set("my_key", "hello world!", version=3, timeout=None)
554+
555+
cache.decr_version("my_key", version=3)
556+
557+
my_value = cache.get("my_key", version=2)
558+
559+
assert my_value == "hello world!"
560+
539561
def test_delete_pattern(self, cache: ValkeyCache):
540562
if isinstance(cache.client, DefaultClusterClient):
541563
pytest.skip("cluster client has a specific test")

tests/test_cache_options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def reverse_key(key: str) -> str:
3636
"hlen",
3737
"incr",
3838
"incr_version",
39+
"decr_version",
3940
"keys",
4041
"lock",
4142
"mget",

tests/tests_async/test_backend.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,28 @@ async def test_ttl_incr_version_no_timeout(self, cache: AsyncValkeyCache):
516516

517517
assert my_value == "hello world!"
518518

519+
async def test_decr_version(self, cache: AsyncValkeyCache):
520+
await cache.aset("keytest", 2, version=3)
521+
res = await cache.aget("keytest", version=3)
522+
assert res == 2
523+
524+
await cache.decr_version("keytest", version=3)
525+
526+
res = await cache.aget("keytest", version=3)
527+
assert res is None
528+
529+
res = await cache.aget("keytest", version=2)
530+
assert res == 2
531+
532+
async def test_ttl_decr_version_no_timeout(self, cache: AsyncValkeyCache):
533+
await cache.set("my_key", "hello world!", timeout=None, version=3)
534+
535+
await cache.adecr_version("my_key", version=3)
536+
537+
my_value = await cache.get("my_key", version=2)
538+
539+
assert my_value == "hello world!"
540+
519541
async def test_delete_pattern(self, cache: AsyncValkeyCache):
520542
for key in ["foo-aa", "foo-ab", "foo-bb", "foo-bc"]:
521543
await cache.aset(key, "foo")

tests/tests_async/test_cache_options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"hlen",
3131
"incr",
3232
"incr_version",
33+
"decr_version",
3334
"keys",
3435
"lock",
3536
"mget",

0 commit comments

Comments
 (0)