This commit is contained in:
Tamil Adhavan S K 2026-09-24 16:53:08 -04:00 • committed by GitHub
commit 1058d63aa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -1785,7 +1785,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

@ -0,0 +1,27 @@
from unittest.mock import AsyncMock, Mock
import pytest
from litellm.caching.redis_cache import RedisCache
@pytest.mark.asyncio
async def test_disconnect_allows_missing_async_pool():
cache = RedisCache.__new__(RedisCache)
cache.async_redis_conn_pool = None
cache.redis_client = Mock()
await cache.disconnect()
cache.redis_client.close.assert_called_once_with()
@pytest.mark.asyncio
async def test_disconnect_closes_present_async_pool():
cache = RedisCache.__new__(RedisCache)
cache.async_redis_conn_pool = Mock(disconnect=AsyncMock())
cache.redis_client = Mock()
await cache.disconnect()
cache.async_redis_conn_pool.disconnect.assert_awaited_once_with(inuse_connections=True)