From c870af768dcf367d8baeeee838adcd90862bb779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=85=E8=AF=BA=E7=8B=90?= <212194964+foxcyber907@users.noreply.github.com> Date: Wed, 10 Dec 2025 15:06:01 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=88redis=EF=BC=89=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0Redis=E8=BF=9E=E6=8E=A5=E6=B1=A0=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E4=BB=A5=E5=85=BC=E5=AE=B9redis-py=207.x?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新Redis连接池创建方式,使用connection_class参数替代已弃用的ssl参数,以适配redis-py 7.x及以上版本 --- src/common/database/optimization/redis_cache.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/database/optimization/redis_cache.py b/src/common/database/optimization/redis_cache.py index 8dd00a44c..558ec8544 100644 --- a/src/common/database/optimization/redis_cache.py +++ b/src/common/database/optimization/redis_cache.py @@ -20,6 +20,7 @@ from src.common.logger import get_logger logger = get_logger("redis_cache") import redis.asyncio as aioredis +from redis.asyncio.connection import Connection, SSLConnection class RedisCache(CacheBackend): @@ -98,7 +99,11 @@ class RedisCache(CacheBackend): return self._client try: - # 创建连接池 (使用 aioredis 模块确保类型安全) + # redis-py 7.x+ 使用 connection_class 来指定 SSL 连接 + # 不再支持直接传递 ssl=True/False 给 ConnectionPool + connection_class = SSLConnection if self.ssl else Connection + + # 创建连接池 self._pool = aioredis.ConnectionPool( host=self.host, port=self.port, @@ -108,7 +113,7 @@ class RedisCache(CacheBackend): socket_timeout=self.socket_timeout, socket_connect_timeout=self.socket_timeout, decode_responses=False, # 我们自己处理序列化 - ssl=self.ssl, + connection_class=connection_class, ) # 创建客户端