Skip to content

Commit b7ebfe0

Browse files
authored
Merge branch 'main' into free-threaded-python3.14t
2 parents 8b826eb + aaf4767 commit b7ebfe0

File tree

11 files changed

+87
-10
lines changed

11 files changed

+87
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
mkdir -p ./custom-cache/
2222
docker compose --profile all build
2323
docker pull valkey/valkey:latest
24-
docker pull bitnami/valkey-cluster:8.1
25-
docker save bitnami/valkey-cluster valkey/valkey:latest -o ./custom-cache/all.tar
24+
docker pull bitnamilegacy/valkey-cluster:8.1
25+
docker save bitnamilegacy/valkey-cluster valkey/valkey:latest -o ./custom-cache/all.tar
2626
2727
test:
2828
runs-on: ubuntu-latest

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 0.3.2
2+
-------------
3+
4+
- add `decr_version` method to be compatible with django's `BaseCache`
5+
16
Version 0.3.1
27
-------------
38

compose.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
retries: 5
2323

2424
valkey-node-0:
25-
image: bitnami/valkey-cluster:8.1
25+
image: bitnamilegacy/valkey-cluster:8.1
2626
environment:
2727
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"
2828
- "ALLOW_EMPTY_PASSWORD=yes"
@@ -35,7 +35,7 @@ services:
3535
- all
3636

3737
valkey-node-1:
38-
image: bitnami/valkey-cluster:8.1
38+
image: bitnamilegacy/valkey-cluster:8.1
3939
environment:
4040
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"
4141
- "ALLOW_EMPTY_PASSWORD=yes"
@@ -49,7 +49,7 @@ services:
4949
- all
5050

5151
valkey-node-2:
52-
image: bitnami/valkey-cluster:8.1
52+
image: bitnamilegacy/valkey-cluster:8.1
5353
environment:
5454
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"
5555
- "ALLOW_EMPTY_PASSWORD=yes"
@@ -62,7 +62,7 @@ services:
6262
- all
6363

6464
valkey-node-3:
65-
image: bitnami/valkey-cluster:8.1
65+
image: bitnamilegacy/valkey-cluster:8.1
6666
environment:
6767
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"
6868
- "ALLOW_EMPTY_PASSWORD=yes"
@@ -77,7 +77,7 @@ services:
7777
- all
7878

7979
valkey-node-4:
80-
image: bitnami/valkey-cluster:8.1
80+
image: bitnamilegacy/valkey-cluster:8.1
8181
environment:
8282
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"
8383
- "ALLOW_EMPTY_PASSWORD=yes"
@@ -90,7 +90,7 @@ services:
9090
- all
9191

9292
valkey-node-5:
93-
image: bitnami/valkey-cluster:8.1
93+
image: bitnamilegacy/valkey-cluster:8.1
9494
environment:
9595
- "VALKEY_CLUSTER_REPLICAS=1"
9696
- "VALKEY_NODES=valkey-node-0 valkey-node-1 valkey-node-2 valkey-node-3 valkey-node-4 valkey-node-5"

django_valkey/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (0, 3, 1)
1+
VERSION = (0, 3, 2)
22
__version__ = ".".join(map(str, VERSION))
33

44

django_valkey/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def set(self: BaseValkeyCache, *args, **kwargs) -> bool:
210210
def incr_version(self: BaseValkeyCache, *args, **kwargs) -> int:
211211
return self.client.incr_version(*args, **kwargs)
212212

213+
def decr_version(self: BaseValkeyCache, *args, **kwargs) -> int:
214+
return self.client.decr_version(*args, **kwargs)
215+
213216
def add(self: BaseValkeyCache, *args, **kwargs) -> bool:
214217
return self.client.add(*args, **kwargs)
215218

@@ -398,6 +401,9 @@ async def set(self: BaseValkeyCache, *args, **kwargs):
398401
async def incr_version(self, *args, **kwargs):
399402
return await self.client.aincr_version(*args, **kwargs)
400403

404+
async def decr_version(self, *args, **kwargs):
405+
return await self.client.adecr_version(*args, **kwargs)
406+
401407
async def add(self, *args, **kwargs):
402408
return await self.client.aadd(*args, **kwargs)
403409

django_valkey/base_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ def incr_version(
331331
self.delete(old_key, client=client)
332332
return version + delta
333333

334+
def decr_version(
335+
self: BaseClient,
336+
key: KeyT,
337+
delta: int = 1,
338+
version: int | None = None,
339+
client: Backend | Any | None = None,
340+
) -> int:
341+
return self.incr_version(key=key, delta=-delta, version=version, client=client)
342+
334343
def _incr_version(
335344
self: BaseClient,
336345
key: KeyT,
@@ -1464,6 +1473,17 @@ async def incr_version(
14641473
await self.delete(old_key, client=client)
14651474
return version + delta
14661475

1476+
async def decr_version(
1477+
self: BaseClient,
1478+
key: KeyT,
1479+
delta: int = 1,
1480+
version: int | None = None,
1481+
client: Backend | Any | None = None,
1482+
) -> int:
1483+
return await self.incr_version(
1484+
key=key, delta=-delta, version=version, client=client
1485+
)
1486+
14671487
async def _incr_version(self, key, delta, version, client) -> tuple:
14681488
if version is None:
14691489
version = self._backend.version

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "django-valkey"
7-
version = "0.3.1"
7+
version = "0.3.2"
88
description = "a valkey backend for django"
99
readme = "README.rst"
1010
requires-python = ">=3.10"

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")

0 commit comments

Comments
 (0)