mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
* update RedisCluster creation * update RedisClusterCache * add redis ClusterCache * update async_set_cache_pipeline * cleanup redis cluster usage * fix redis pipeline * test_init_async_client_returns_same_instance * fix redis cluster * update mypy_path * fix init_redis_cluster * remove stub * test redis commit * ClusterPipeline * fix import * RedisCluster import * fix redis cluster * Potential fix for code scanning alert no. 2129: Clear-text logging of sensitive information Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix naming of redis cluster integration * test_redis_caching_ttl_pipeline * fix async_set_cache_pipeline --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""
|
|
Redis Cluster Cache implementation
|
|
|
|
Key differences:
|
|
- RedisClient NEEDs to be re-used across requests, adds 3000ms latency if it's re-created
|
|
"""
|
|
|
|
from typing import TYPE_CHECKING, Any, Optional
|
|
|
|
from litellm.caching.redis_cache import RedisCache
|
|
|
|
if TYPE_CHECKING:
|
|
from opentelemetry.trace import Span as _Span
|
|
from redis.asyncio import Redis, RedisCluster
|
|
from redis.asyncio.client import Pipeline
|
|
|
|
pipeline = Pipeline
|
|
async_redis_client = Redis
|
|
Span = _Span
|
|
else:
|
|
pipeline = Any
|
|
async_redis_client = Any
|
|
Span = Any
|
|
|
|
|
|
class RedisClusterCache(RedisCache):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.redis_cluster_client: Optional[RedisCluster] = None
|
|
|
|
def init_async_client(self):
|
|
from redis.asyncio import RedisCluster
|
|
|
|
from .._redis import get_redis_async_client
|
|
|
|
if self.redis_cluster_client:
|
|
return self.redis_cluster_client
|
|
|
|
_redis_client = get_redis_async_client(
|
|
connection_pool=self.async_redis_conn_pool, **self.redis_kwargs
|
|
)
|
|
if isinstance(_redis_client, RedisCluster):
|
|
self.redis_cluster_client = _redis_client
|
|
return _redis_client
|