Initial commit: stock market platform
This commit is contained in:
22
backend/app/core/redis.py
Normal file
22
backend/app/core/redis.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
Reference in New Issue
Block a user