redis connection + queue
This commit is contained in:
1
framework/__init__.py
Normal file
1
framework/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .redis import Redis
|
24
framework/redis.py
Normal file
24
framework/redis.py
Normal file
@ -0,0 +1,24 @@
|
||||
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()
|
Reference in New Issue
Block a user