Skip to content

Commit

Permalink
test mset, mget
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Sep 30, 2024
1 parent f1204eb commit 2fef051
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 9 deletions.
39 changes: 39 additions & 0 deletions tests/settings/sqlite_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
SECRET_KEY = "django_tests_secret_key"

CACHES = {
"default": {
"BACKEND": "django_valkey.cache.ValkeyCache",
"LOCATION": ["valkey://127.0.0.1:6379", "valkey://127.0.0.1:6379"],
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
},
"doesnotexist": {
"BACKEND": "django_valkey.cache.ValkeyCache",
"LOCATION": "valkey://127.0.0.1:56379?db=1",
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
},
"sample": {
"BACKEND": "django_valkey.cache.ValkeyCache",
"LOCATION": "valkey://127.0.0.1:6379:1,valkey://127.0.0.1:6379:1",
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
},
"with_prefix": {
"BACKEND": "django_valkey.cache.ValkeyCache",
"LOCATION": "valkey://127.0.0.1:6379?db=1",
"OPTIONS": {"CLIENT_CLASS": "django_valkey.client.DefaultClient"},
"KEY_PREFIX": "test-prefix",
},
}

# Include `django.contrib.auth` and `django.contrib.contenttypes` for mypy /
# django-stubs.

# See:
# - https://github.com/typeddjango/django-stubs/issues/318
# - https://github.com/typeddjango/django-stubs/issues/534
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
]

USE_TZ = False
25 changes: 21 additions & 4 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,36 @@ def test_get_many(self, cache: ValkeyCache):
res = cache.get_many(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

def test_mget(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip()
cache.set("a", 1)
cache.set("b", 2)
cache.set("c", 3)

res = cache.mget(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

def test_get_many_unicode(self, cache: ValkeyCache):
cache.set("a", "1")
cache.set("b", "2")
cache.set("c", "3")
cache.set("ب", "2")
cache.set("c", "الف")

res = cache.get_many(["a", "b", "c"])
assert res == {"a": "1", "b": "2", "c": "3"}
res = cache.get_many(["a", "ب", "c"])
assert res == {"a": "1", "ب": "2", "c": "الف"}

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

def test_mset(self, cache: ValkeyCache):
if isinstance(cache.client, ShardClient):
pytest.skip()
cache.mset({"a": 1, "b": 2, "c": 3})
res = cache.mget(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

def test_set_call_empty_pipeline(
self,
cache: ValkeyCache,
Expand Down
31 changes: 26 additions & 5 deletions tests/tests_async/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,40 @@ async def test_get_many(self, cache: AsyncValkeyCache):
res = await cache.aget_many(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

async def test_mget(self, cache: AsyncValkeyCache):
await cache.aset("a", 1)
await cache.aset("b", 2)
await cache.aset("c", 3)

res = await cache.mget(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

async def test_get_many_unicode(self, cache: AsyncValkeyCache):
await cache.aset("a", "1")
await cache.aset("b", "2")
await cache.aset("c", "3")
await cache.aset("ب", "2")
await cache.aset("c", "الف")

res = await cache.aget_many(["a", "b", "c"])
assert res == {"a": "1", "b": "2", "c": "3"}
res = await cache.aget_many(["a", "ب", "c"])
assert res == {"a": "1", "ب": "2", "c": "الف"}

async def test_mget_unicode(self, cache: AsyncValkeyCache):
await cache.aset("a", "1")
await cache.aset("ب", "2")
await cache.aset("c", "الف")

res = await cache.mget(["a", "ب", "c"])
assert res == {"a": "1", "ب": "2", "c": "الف"}

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

async def test_mset(self, cache: AsyncValkeyCache):
await cache.amset({"a": 1, "b": 2, "c": 3})
res = await cache.aget_many(["a", "b", "c"])
assert res == {"a": 1, "b": 2, "c": 3}

async def test_set_call_empty_pipeline(
self,
cache: AsyncValkeyCache,
Expand Down Expand Up @@ -823,7 +844,7 @@ async def test_clear(self, cache: AsyncValkeyCache):
async def test_hset(self, cache: AsyncValkeyCache):
# if isinstance(cache.client, ShardClient):
# pytest.skip("ShardClient doesn't support get_client")
await cache.ahset("foo_hash1", "foo1", "bar1")
assert await cache.ahset("foo_hash1", "foo1", "bar1") == 1
await cache.ahset("foo_hash1", "foo2", "bar2")
assert await cache.ahlen("foo_hash1") == 2
assert await cache.ahexists("foo_hash1", "foo1")
Expand Down

0 comments on commit 2fef051

Please sign in to comment.