Files
stock/backend/app/core/redis.py
2026-06-11 01:41:47 +08:00

23 lines
518 B
Python

import redis.asyncio as aioredis
from app.core.config import settings
_redis_pool: aioredis.Redis | None = None
async def get_redis() -> aioredis.Redis:
global _redis_pool
if _redis_pool is None:
_redis_pool = aioredis.from_url(
settings.REDIS_URL,
encoding="utf-8",
decode_responses=True,
)
return _redis_pool
async def close_redis() -> None:
global _redis_pool
if _redis_pool:
await _redis_pool.aclose()
_redis_pool = None