forked from phoenix/litellm-mirror
(redis fix) - fix AbstractConnection.__init__() got an unexpected keyword argument 'ssl'
(#6908)
* add better debugging for get_redis_connection_pool + allow passing ssl=None * test_redis_with_ssl * test_redis_with_ssl * test_redis_with_ssl
This commit is contained in:
parent
552c0dd7a4
commit
5c854650c2
2 changed files with 28 additions and 1 deletions
|
@ -313,12 +313,13 @@ def get_redis_async_client(**env_overrides) -> async_redis.Redis:
|
||||||
|
|
||||||
def get_redis_connection_pool(**env_overrides):
|
def get_redis_connection_pool(**env_overrides):
|
||||||
redis_kwargs = _get_redis_client_logic(**env_overrides)
|
redis_kwargs = _get_redis_client_logic(**env_overrides)
|
||||||
|
verbose_logger.debug("get_redis_connection_pool: redis_kwargs", redis_kwargs)
|
||||||
if "url" in redis_kwargs and redis_kwargs["url"] is not None:
|
if "url" in redis_kwargs and redis_kwargs["url"] is not None:
|
||||||
return async_redis.BlockingConnectionPool.from_url(
|
return async_redis.BlockingConnectionPool.from_url(
|
||||||
timeout=5, url=redis_kwargs["url"]
|
timeout=5, url=redis_kwargs["url"]
|
||||||
)
|
)
|
||||||
connection_class = async_redis.Connection
|
connection_class = async_redis.Connection
|
||||||
if "ssl" in redis_kwargs and redis_kwargs["ssl"] is not None:
|
if "ssl" in redis_kwargs:
|
||||||
connection_class = async_redis.SSLConnection
|
connection_class = async_redis.SSLConnection
|
||||||
redis_kwargs.pop("ssl", None)
|
redis_kwargs.pop("ssl", None)
|
||||||
redis_kwargs["connection_class"] = connection_class
|
redis_kwargs["connection_class"] = connection_class
|
||||||
|
|
|
@ -99,3 +99,29 @@ def test_caching_router():
|
||||||
|
|
||||||
|
|
||||||
# test_caching_router()
|
# test_caching_router()
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_redis_with_ssl():
|
||||||
|
"""
|
||||||
|
Test connecting to redis connection pool when ssl=None
|
||||||
|
|
||||||
|
|
||||||
|
Relevant issue:
|
||||||
|
User was seeing this error: `TypeError: AbstractConnection.__init__() got an unexpected keyword argument 'ssl'`
|
||||||
|
"""
|
||||||
|
from litellm._redis import get_redis_connection_pool, get_redis_async_client
|
||||||
|
|
||||||
|
# Get the connection pool with SSL
|
||||||
|
# REDIS_HOST_WITH_SSL is just a redis cloud instance with Transport layer security (TLS) enabled
|
||||||
|
pool = get_redis_connection_pool(
|
||||||
|
host=os.environ.get("REDIS_HOST_WITH_SSL"),
|
||||||
|
port=os.environ.get("REDIS_PORT_WITH_SSL"),
|
||||||
|
password=os.environ.get("REDIS_PASSWORD_WITH_SSL"),
|
||||||
|
ssl=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create Redis client with the pool
|
||||||
|
redis_client = get_redis_async_client(connection_pool=pool)
|
||||||
|
|
||||||
|
print("pinging redis")
|
||||||
|
print(await redis_client.ping())
|
||||||
|
print("pinged redis")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue