refactor(message): replace synchronous Redis client with asynchronous client
This commit is contained in:
@@ -9,7 +9,6 @@ from app.config import settings
|
||||
|
||||
from fastapi import Depends
|
||||
from pydantic import BaseModel
|
||||
import redis as sync_redis
|
||||
import redis.asyncio as redis
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlmodel import SQLModel
|
||||
@@ -41,8 +40,8 @@ redis_client = redis.from_url(settings.redis_url, decode_responses=True)
|
||||
# Redis 二进制数据连接 (不自动解码响应,用于存储音频等二进制数据)
|
||||
redis_binary_client = redis.from_url(settings.redis_url, decode_responses=False)
|
||||
|
||||
# Redis 消息缓存连接 (db1) - 使用同步客户端在线程池中执行
|
||||
redis_message_client = sync_redis.from_url(settings.redis_url, decode_responses=True, db=1)
|
||||
# Redis 消息缓存连接 (db1)
|
||||
redis_message_client: redis.Redis = redis.from_url(settings.redis_url, decode_responses=True, db=1)
|
||||
|
||||
|
||||
# 数据库依赖
|
||||
@@ -97,7 +96,7 @@ def get_redis_binary():
|
||||
return redis_binary_client
|
||||
|
||||
|
||||
def get_redis_message():
|
||||
def get_redis_message() -> redis.Redis:
|
||||
"""获取消息专用的 Redis 客户端 (db1)"""
|
||||
return redis_message_client
|
||||
|
||||
|
||||
Reference in New Issue
Block a user