mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
Merge 21af87fad9 into 5337c68dd3
This commit is contained in:
commit
cd7650e3f6
3 changed files with 23 additions and 0 deletions
|
|
@ -1370,6 +1370,8 @@ class RedisCache(BaseCache):
|
|||
self.redis_client.flushall()
|
||||
|
||||
async def disconnect(self):
|
||||
if self.async_redis_conn_pool is None:
|
||||
return
|
||||
await self.async_redis_conn_pool.disconnect(inuse_connections=True)
|
||||
try:
|
||||
self.redis_client.close()
|
||||
|
|
|
|||
|
|
@ -56,6 +56,16 @@ 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):
|
||||
if self.redis_async_redis_cluster_client is not None:
|
||||
await self.redis_async_redis_cluster_client.aclose()
|
||||
try:
|
||||
self.redis_client.close()
|
||||
except Exception as e:
|
||||
from litellm._logging import verbose_logger
|
||||
|
||||
verbose_logger.debug("Error closing sync Redis Cluster client: %s", e)
|
||||
|
||||
async def test_connection(self) -> dict:
|
||||
"""
|
||||
Test the Redis Cluster connection.
|
||||
|
|
|
|||
|
|
@ -464,6 +464,17 @@ def test_delete_cache_namespaces_key(namespace, expected, monkeypatch, redis_no_
|
|||
redis_cache.delete_cache(key="k")
|
||||
mock_client.delete.assert_called_once_with(expected)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_disconnect_with_none_conn_pool():
|
||||
"""Regression test: disconnect() must not raise AttributeError when async_redis_conn_pool is None (cluster mode)."""
|
||||
with patch("asyncio.get_running_loop", side_effect=RuntimeError):
|
||||
cache = RedisCache(host="localhost", port=6379, password="x")
|
||||
|
||||
cache.async_redis_conn_pool = None
|
||||
|
||||
# Should return without raising
|
||||
await cache.disconnect()
|
||||
|
||||
|
||||
def _closed_port() -> int:
|
||||
"""A port with nothing listening, so Redis calls fail fast and deterministically."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue