封装 redis 客户端处理方案
This commit is contained in:
@@ -9,7 +9,7 @@ from app.core.logger import log
|
||||
async def lifespan(app: FastAPI):
|
||||
"""应用生命周期管理:初始化和释放所有连接资源"""
|
||||
from app.core.database import init_db, close_db
|
||||
from app.core.redis import init_redis, close_redis
|
||||
from app.core.redis import RedisManager
|
||||
from pathlib import Path
|
||||
|
||||
# 启动:初始化资源
|
||||
@@ -22,7 +22,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
try:
|
||||
log.info("初始化redis连接")
|
||||
await init_redis()
|
||||
await RedisManager.init()
|
||||
except Exception as e:
|
||||
log.warning(f"Redis 连接初始化失败: {e}")
|
||||
raise e
|
||||
@@ -39,5 +39,5 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
# 关闭:释放资源
|
||||
await close_db()
|
||||
await close_redis()
|
||||
await RedisManager.close()
|
||||
log.info("所有连接资源已释放")
|
||||
|
||||
Reference in New Issue
Block a user