redis.py 373 B

123456789101112131415
  1. from typing import Optional
  2. from redis.asyncio import Redis
  3. from app.core.config import settings
  4. _redis_client: Optional[Redis] = None
  5. async def get_redis_client() -> Redis:
  6. global _redis_client
  7. if _redis_client is None:
  8. _redis_client = Redis.from_url(
  9. settings.redis_url,
  10. decode_responses=True
  11. )
  12. return _redis_client