Refactor Phase 2: Split stories.py into Schema/Service/Controller, add missing endpoints, fix async bug
This commit is contained in:
25
backend/app/core/redis.py
Normal file
25
backend/app/core/redis.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Redis client module."""
|
||||
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from redis.asyncio import Redis, from_url
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
_redis_pool: Redis | None = None
|
||||
|
||||
|
||||
async def get_redis() -> Redis:
|
||||
"""Get global Redis client instance."""
|
||||
global _redis_pool
|
||||
if _redis_pool is None:
|
||||
_redis_pool = from_url(settings.redis_url, encoding="utf-8", decode_responses=True)
|
||||
return _redis_pool
|
||||
|
||||
|
||||
async def close_redis():
|
||||
"""Close Redis connection."""
|
||||
global _redis_pool
|
||||
if _redis_pool:
|
||||
await _redis_pool.close()
|
||||
_redis_pool = None
|
||||
Reference in New Issue
Block a user