Refactor stream notifier

This commit is contained in:
2024-11-17 22:00:28 +01:00
parent 95152c15a7
commit b3bc07f7db
15 changed files with 470 additions and 216 deletions

33
src/core/redis.py Normal file
View File

@@ -0,0 +1,33 @@
import contextlib
from redis.asyncio import from_url
from core.config import config
def create_redis_pool():
return from_url(config.REDIS_URI)
class RedisSessionManager:
def __init__(self):
self.pool = None
async def init(self):
self.pool = await create_redis_pool()
async def close(self):
if self.pool is not None:
await self.pool.close()
@contextlib.asynccontextmanager
async def connect(self):
if self.pool is None:
await self.init()
assert self.pool is not None
yield self.pool
redis_manager = RedisSessionManager()