Skip to content

Commit 3166e84

Browse files
committed
Add make_key/make_pattern to BackendCommands
1 parent 2340bbb commit 3166e84

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

django_valkey/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ def client(self) -> Client:
192192
self._client = self._client_cls(self._server, self._params, self)
193193
return self._client
194194

195+
def make_key(self, *args, **kwargs) -> bool:
196+
return self.client.make_key(*args, **kwargs)
197+
198+
def make_pattern(self, *args, **kwargs) -> bool:
199+
return self.client.make_pattern(*args, **kwargs)
200+
195201

196202
@decorate_all_methods(omit_exception)
197203
class BackendCommands:

tests/test_backend.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,3 +1208,11 @@ def test_sunionstore(self, cache: ValkeyCache):
12081208
cache.sadd("foo2", "bar2", "bar3")
12091209
assert cache.sunionstore("foo3", "foo1", "foo2") == 3
12101210
assert cache.smembers("foo3") == {"bar1", "bar2", "bar3"}
1211+
1212+
def test_make_key(self, cache: ValkeyCache):
1213+
assert cache.make_key("key", version=1, prefix="prefix") == "prefix:1:key"
1214+
1215+
def test_make_pattern(self, cache: ValkeyCache):
1216+
assert (
1217+
cache.make_pattern("key_*", version=1, prefix="prefix") == "prefix:1:key_*"
1218+
)

tests/tests_async/test_backend.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,11 @@ async def test_sunionstore(self, cache: AsyncValkeyCache):
10411041
await cache.asadd("foo2", "bar2", "bar3")
10421042
assert await cache.asunionstore("foo3", "foo1", "foo2") == 3
10431043
assert await cache.asmembers("foo3") == {"bar1", "bar2", "bar3"}
1044+
1045+
async def test_make_key(self, cache: AsyncValkeyCache):
1046+
assert cache.make_key("key", version=1, prefix="prefix") == "prefix:1:key"
1047+
1048+
async def test_make_pattern(self, cache: AsyncValkeyCache):
1049+
assert (
1050+
cache.make_pattern("key_*", version=1, prefix="prefix") == "prefix:1:key_*"
1051+
)

0 commit comments

Comments
 (0)