mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
Merge 5e843bcfde into 5e4b1b9df0
This commit is contained in:
commit
1058d63aa5
2 changed files with 29 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
27
tests/test_litellm/test_redis_disconnect.py
Normal file
27
tests/test_litellm/test_redis_disconnect.py
Normal 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)
|
||||
Loading…
Add table
Reference in a new issue