Skip to content

Commit 2fef051

Browse files
committed
test mset, mget
1 parent f1204eb commit 2fef051

File tree

3 files changed

+86
-9
lines changed

3 files changed

+86
-9
lines changed

tests/settings/sqlite_cluster.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
SECRET_KEY = "django_tests_secret_key"
2+
3+
CACHES = {
4+
"default": {
5+
"BACKEND": "django_valkey.cache.ValkeyCache",
6+
"LOCATION": ["valkey://127.0.0.1:6379", "valkey://127.0.0.1:6379"],
7+
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
8+
},
9+
"doesnotexist": {
10+
"BACKEND": "django_valkey.cache.ValkeyCache",
11+
"LOCATION": "valkey://127.0.0.1:56379?db=1",
12+
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
13+
},
14+
"sample": {
15+
"BACKEND": "django_valkey.cache.ValkeyCache",
16+
"LOCATION": "valkey://127.0.0.1:6379:1,valkey://127.0.0.1:6379:1",
17+
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
18+
},
19+
"with_prefix": {
20+
"BACKEND": "django_valkey.cache.ValkeyCache",
21+
"LOCATION": "valkey://127.0.0.1:6379?db=1",
22+
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
23+
"KEY_PREFIX": "test-prefix",
24+
},
25+
}
26+
27+
# Include `django.contrib.auth` and `django.contrib.contenttypes` for mypy /
28+
# django-stubs.
29+
30+
# See:
31+
# - https://github.com/typeddjango/django-stubs/issues/318
32+
# - https://github.com/typeddjango/django-stubs/issues/534
33+
INSTALLED_APPS = [
34+
"django.contrib.auth",
35+
"django.contrib.contenttypes",
36+
"django.contrib.sessions",
37+
]
38+
39+
USE_TZ = False

tests/test_backend.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,36 @@ def test_get_many(self, cache: ValkeyCache):
196196
res = cache.get_many(["a", "b", "c"])
197197
assert res == {"a": 1, "b": 2, "c": 3}
198198

199+
def test_mget(self, cache: ValkeyCache):
200+
if isinstance(cache.client, ShardClient):
201+
pytest.skip()
202+
cache.set("a", 1)
203+
cache.set("b", 2)
204+
cache.set("c", 3)
205+
206+
res = cache.mget(["a", "b", "c"])
207+
assert res == {"a": 1, "b": 2, "c": 3}
208+
199209
def test_get_many_unicode(self, cache: ValkeyCache):
200210
cache.set("a", "1")
201-
cache.set("b", "2")
202-
cache.set("c", "3")
211+
cache.set("ب", "2")
212+
cache.set("c", "الف")
203213

204-
res = cache.get_many(["a", "b", "c"])
205-
assert res == {"a": "1", "b": "2", "c": "3"}
214+
res = cache.get_many(["a", "ب", "c"])
215+
assert res == {"a": "1", "ب": "2", "c": "الف"}
206216

207217
def test_set_many(self, cache: ValkeyCache):
208218
cache.set_many({"a": 1, "b": 2, "c": 3})
209219
res = cache.get_many(["a", "b", "c"])
210220
assert res == {"a": 1, "b": 2, "c": 3}
211221

222+
def test_mset(self, cache: ValkeyCache):
223+
if isinstance(cache.client, ShardClient):
224+
pytest.skip()
225+
cache.mset({"a": 1, "b": 2, "c": 3})
226+
res = cache.mget(["a", "b", "c"])
227+
assert res == {"a": 1, "b": 2, "c": 3}
228+
212229
def test_set_call_empty_pipeline(
213230
self,
214231
cache: ValkeyCache,

tests/tests_async/test_backend.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,40 @@ async def test_get_many(self, cache: AsyncValkeyCache):
199199
res = await cache.aget_many(["a", "b", "c"])
200200
assert res == {"a": 1, "b": 2, "c": 3}
201201

202+
async def test_mget(self, cache: AsyncValkeyCache):
203+
await cache.aset("a", 1)
204+
await cache.aset("b", 2)
205+
await cache.aset("c", 3)
206+
207+
res = await cache.mget(["a", "b", "c"])
208+
assert res == {"a": 1, "b": 2, "c": 3}
209+
202210
async def test_get_many_unicode(self, cache: AsyncValkeyCache):
203211
await cache.aset("a", "1")
204-
await cache.aset("b", "2")
205-
await cache.aset("c", "3")
212+
await cache.aset("ب", "2")
213+
await cache.aset("c", "الف")
206214

207-
res = await cache.aget_many(["a", "b", "c"])
208-
assert res == {"a": "1", "b": "2", "c": "3"}
215+
res = await cache.aget_many(["a", "ب", "c"])
216+
assert res == {"a": "1", "ب": "2", "c": "الف"}
217+
218+
async def test_mget_unicode(self, cache: AsyncValkeyCache):
219+
await cache.aset("a", "1")
220+
await cache.aset("ب", "2")
221+
await cache.aset("c", "الف")
222+
223+
res = await cache.mget(["a", "ب", "c"])
224+
assert res == {"a": "1", "ب": "2", "c": "الف"}
209225

210226
async def test_set_many(self, cache: AsyncValkeyCache):
211227
await cache.aset_many({"a": 1, "b": 2, "c": 3})
212228
res = await cache.aget_many(["a", "b", "c"])
213229
assert res == {"a": 1, "b": 2, "c": 3}
214230

231+
async def test_mset(self, cache: AsyncValkeyCache):
232+
await cache.amset({"a": 1, "b": 2, "c": 3})
233+
res = await cache.aget_many(["a", "b", "c"])
234+
assert res == {"a": 1, "b": 2, "c": 3}
235+
215236
async def test_set_call_empty_pipeline(
216237
self,
217238
cache: AsyncValkeyCache,
@@ -823,7 +844,7 @@ async def test_clear(self, cache: AsyncValkeyCache):
823844
async def test_hset(self, cache: AsyncValkeyCache):
824845
# if isinstance(cache.client, ShardClient):
825846
# pytest.skip("ShardClient doesn't support get_client")
826-
await cache.ahset("foo_hash1", "foo1", "bar1")
847+
assert await cache.ahset("foo_hash1", "foo1", "bar1") == 1
827848
await cache.ahset("foo_hash1", "foo2", "bar2")
828849
assert await cache.ahlen("foo_hash1") == 2
829850
assert await cache.ahexists("foo_hash1", "foo1")

0 commit comments

Comments
 (0)