from app.config import settings import redis.asyncio as aioredis from redis.asyncio import ConnectionPool _pool = None async def get_redis(): global _pool if _pool is None: _pool = ConnectionPool.from_url(settings.REDIS_URL, max_connections=20) return aioredis.Redis(connection_pool=_pool) async def close_redis(): global _pool if _pool: await _pool.disconnect() _pool = None