Skip to content

Commit

Permalink
adjust the clients to be compatible with default clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Jan 7, 2025
1 parent 0b4d8dd commit 4a639a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 6 additions & 5 deletions django_valkey/async_cache/client/herd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from typing import Tuple, Any

from django.conf import settings
from django.core.cache.backends.base import DEFAULT_TIMEOUT

from valkey import Valkey
from valkey.exceptions import ConnectionError, ResponseError, TimeoutError
from valkey.typing import EncodableT

from django_valkey.async_cache.client import AsyncDefaultClient
from django_valkey.base_client import DEFAULT_TIMEOUT
from django_valkey.client.herd import Marker, _is_expired
from django_valkey.exceptions import ConnectionInterrupted
from django_valkey.typing import KeyT
Expand Down Expand Up @@ -102,7 +103,7 @@ async def aget_many(self, keys, version=None, client=None):

recovered_data = {}

new_keys = [await self.make_key(key, version=version) for key in keys]
new_keys = [self.make_key(key, version=version) for key in keys]
map_keys = dict(zip(new_keys, keys))

try:
Expand All @@ -117,7 +118,7 @@ async def aget_many(self, keys, version=None, client=None):
if value is None:
continue

val, refresh = await self._unpack(await self.decode(value))
val, refresh = await self._unpack(self.decode(value))
recovered_data[map_keys[key]] = None if refresh else val

return recovered_data
Expand All @@ -132,7 +133,7 @@ async def amget(self, keys, version=None, client=None):

recovered_data = {}

new_keys = [await self.make_key(key, version=version) for key in keys]
new_keys = [self.make_key(key, version=version) for key in keys]
map_keys = dict(zip(new_keys, keys))

try:
Expand All @@ -144,7 +145,7 @@ async def amget(self, keys, version=None, client=None):
if value is None:
continue

val, refresh = await self._unpack(await self.decode(value))
val, refresh = await self._unpack(self.decode(value))
recovered_data[map_keys[key]] = None if refresh else val

return recovered_data
Expand Down
18 changes: 15 additions & 3 deletions django_valkey/client/herd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from typing import Tuple, Any, Iterable

from django.conf import settings
from django.core.cache.backends.base import DEFAULT_TIMEOUT

from valkey import Valkey
from valkey.exceptions import ConnectionError, ResponseError, TimeoutError
from valkey.typing import EncodableT

from django_valkey.base_client import DEFAULT_TIMEOUT, Backend
from django_valkey.client.default import DefaultClient
from django_valkey.exceptions import ConnectionInterrupted
from django_valkey.typing import KeyT
Expand Down Expand Up @@ -139,8 +140,9 @@ def mget(
self,
keys: Iterable[KeyT],
version: int | None = None,
client: Backend | Any | None = None,
) -> dict:
client: Valkey | Any | None = None,
return_list: bool = False,
) -> dict | list:
client = self._get_client(write=False, client=client)
if not keys:
return {}
Expand All @@ -154,6 +156,16 @@ def mget(
except _main_exceptions as e:
raise ConnectionInterrupted(connection=client) from e

if return_list:
value_list = []
for r in results:
val, refresh = self._unpack(self.decode(r))
if refresh:
value_list.append(None)
else:
value_list.append(val)
return value_list

for key, value in zip(keys, results):
if value is None:
continue
Expand Down
3 changes: 2 additions & 1 deletion django_valkey/client/sharded.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from datetime import datetime, timedelta
from typing import Any

from django.core.cache.backends.base import DEFAULT_TIMEOUT

from valkey import Valkey
from valkey.exceptions import ConnectionError
from valkey.typing import EncodableT

from django_valkey.base_client import DEFAULT_TIMEOUT
from django_valkey.client.default import DefaultClient
from django_valkey.exceptions import ConnectionInterrupted
from django_valkey.hash_ring import HashRing
Expand Down

0 comments on commit 4a639a5

Please sign in to comment.