Skip to content

Commit

Permalink
feat(pm2.json):add
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoskys committed Jan 14, 2024
1 parent ce2b7f4 commit ad0c2fb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions llmkira/sdk/cache/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from redis.asyncio.client import Redis
from redis.asyncio.connection import ConnectionPool

from llmkira.sdk.cache.base import AbstractDataClass, PREFIX
from .base import AbstractDataClass, PREFIX


class RedisClientWrapper(AbstractDataClass):
Expand All @@ -35,7 +35,9 @@ def update_backend(self, backend):
async def set_data(self, key, value, timeout=None):
if isinstance(value, (dict, list)):
value = json.dumps(value)
return await self._redis.set(name=f"{self.prefix}{key}", value=value, ex=timeout)
return await self._redis.set(
name=f"{self.prefix}{key}", value=value, ex=timeout
)

async def read_data(self, key) -> Optional[Union[str, dict, int]]:
data = await self._redis.get(self.prefix + str(key))
Expand Down Expand Up @@ -70,6 +72,8 @@ async def lpop_data(self, key) -> Optional[dict]:
return None

async def lrange_data(self, key, start_end: Tuple[int, int] = (0, -1)) -> List[str]:
_items = await self._redis.lrange(self.prefix + str(key), start=start_end[0], end=start_end[1])
_items = await self._redis.lrange(
self.prefix + str(key), start=start_end[0], end=start_end[1]
)
items = [m.decode("utf-8") for m in _items[::-1]]
return items

0 comments on commit ad0c2fb

Please sign in to comment.