14 lines
398 B
Python
14 lines
398 B
Python
"""Redis 连接池与共享访问封装。"""
|
|
import redis.asyncio as aioredis
|
|
|
|
from app.config import settings
|
|
|
|
_pool: aioredis.Redis | None = None
|
|
|
|
|
|
async def get_redis_pool() -> aioredis.Redis:
|
|
"""返回全局共享的 Redis 客户端(懒初始化)。"""
|
|
global _pool
|
|
if _pool is None:
|
|
_pool = aioredis.from_url(settings.redis_url, decode_responses=True)
|
|
return _pool |