fix(caching): guard Redis disconnect when pool is None and close cluster client

This commit is contained in:
chjnett 2026-08-17 18:52:40 +09:00
parent cd63c7e5a7
commit cae46735d7
2 changed files with 15 additions and 1 deletions

View file

@ -1370,7 +1370,8 @@ class RedisCache(BaseCache):
self.redis_client.flushall()
async def disconnect(self):
await self.async_redis_conn_pool.disconnect(inuse_connections=True)
if self.async_redis_conn_pool is not None:
await self.async_redis_conn_pool.disconnect(inuse_connections=True)
try:
self.redis_client.close()
except Exception as e:

View file

@ -56,6 +56,19 @@ class RedisClusterCache(RedisCache):
async_redis_cluster_client: Final = self.init_async_client()
return await async_redis_cluster_client.mget_nonatomic(keys=keys)
async def disconnect(self):
"""
Overrides `disconnect` in redis_cache.py.
In cluster mode ``get_redis_connection_pool`` returns ``None`` (the
``RedisCluster`` client builds its own per-node pools), so the base-class
implementation would dereference ``None``. Close the cluster client instead,
then let the base class tear down the sync client.
"""
if self.redis_async_redis_cluster_client is not None:
await self.redis_async_redis_cluster_client.aclose()
await super().disconnect()
async def test_connection(self) -> dict:
"""
Test the Redis Cluster connection.