Project started 🍾
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
"""Redis adapter: shared connection pool for cache and arq broker."""
|
||||
|
||||
from app.infrastructure.cache.redis import close_redis, get_redis
|
||||
|
||||
__all__ = ["close_redis", "get_redis"]
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"""Redis client provider — a single shared async connection pool."""
|
||||
|
||||
from redis.asyncio import Redis
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
_client: Redis | None = None
|
||||
|
||||
|
||||
def get_redis() -> Redis:
|
||||
"""Return the process-wide Redis client (created on first use)."""
|
||||
global _client
|
||||
if _client is None:
|
||||
_client = Redis.from_url(
|
||||
str(get_settings().redis_url),
|
||||
encoding="utf-8",
|
||||
decode_responses=True,
|
||||
)
|
||||
return _client
|
||||
|
||||
|
||||
async def close_redis() -> None:
|
||||
global _client
|
||||
if _client is not None:
|
||||
await _client.aclose()
|
||||
_client = None
|
||||
Reference in New Issue
Block a user