Spaces:
Build error
Build error
File size: 1,085 Bytes
b7a7f32 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import aioredis
from core import settings
class RedisClient:
def __init__(self, db: int = 0):
self.client = None
self.db = db
async def initialize(self):
self.client = await aioredis.create_redis_pool(
f"redis://{settings.REDIS_HOST}",
db=self.db,
)
async def close(self):
self.client.close()
await self.client.wait_closed()
class RedisChatClient(RedisClient):
def __init__(self):
super().__init__(db=0)
class RedisSessionClient(RedisClient):
def __init__(self):
super().__init__(db=1)
class RedisThrottleClient(RedisClient):
def __init__(self):
super().__init__(db=2)
class RedisCacheClient(RedisClient):
def __init__(self):
super().__init__(db=3)
class RedisGeneral(RedisClient):
def __init__(self):
super().__init__(db=4)
redis_session_client = RedisSessionClient()
redis_chat_client = RedisChatClient()
redis_throttle_client = RedisThrottleClient()
redis_cache_client = RedisCacheClient()
redis_general = RedisGeneral()
|