28 lines
557 B
Python
28 lines
557 B
Python
from __future__ import annotations
|
|
|
|
from redis.asyncio import Redis, from_url
|
|
|
|
from app.core.config import settings
|
|
|
|
redis_client: Redis | None = None
|
|
|
|
|
|
async def init_redis() -> None:
|
|
global redis_client
|
|
redis_client = from_url(
|
|
settings.REDIS_URL,
|
|
encoding="utf-8",
|
|
decode_responses=True,
|
|
)
|
|
|
|
|
|
async def close_redis() -> None:
|
|
global redis_client
|
|
if redis_client:
|
|
await redis_client.close()
|
|
|
|
|
|
def get_redis() -> Redis:
|
|
assert redis_client is not None, "Redis not initialized"
|
|
return redis_client
|