forked from BerriAI/litellm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Redis Cluster) - Fixes for using redis cluster + pipeline (BerriAI#8442
) * 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>
- Loading branch information
1 parent
de354ab
commit 8ac6b97
Showing
7 changed files
with
112 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[mypy] | ||
warn_return_any = False | ||
ignore_missing_imports = True | ||
mypy_path = litellm/stubs | ||
|
||
[mypy-google.*] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters