25 lines
636 B
Python
25 lines
636 B
Python
import redis.asyncio as redis
|
|
import pickle
|
|
|
|
from config import RedisConfig
|
|
|
|
|
|
class Redis:
|
|
def __init__(self, config: RedisConfig) -> None:
|
|
self.client = redis.Redis(
|
|
host=config.host,
|
|
port=config.port,
|
|
password=config.password,
|
|
auto_close_connection_pool=False,
|
|
)
|
|
|
|
async def set(self, key: str, value: any) -> None:
|
|
await self.client.set(key, pickle.dumps(value))
|
|
|
|
async def get(self, key: str) -> any:
|
|
value = await self.client.get(key)
|
|
return pickle.loads(value)
|
|
|
|
async def close(self) -> None:
|
|
await self.client.close()
|