From 163c6e10655549681e3d33ded391cccc9d54a8f2 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 25 Nov 2024 20:55:57 -0800 Subject: [PATCH 1/4] add better debugging for get_redis_connection_pool + allow passing ssl=None --- litellm/_redis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/_redis.py b/litellm/_redis.py index 2fba9d146..d905f1c9d 100644 --- a/litellm/_redis.py +++ b/litellm/_redis.py @@ -313,12 +313,13 @@ def get_redis_async_client(**env_overrides) -> async_redis.Redis: def get_redis_connection_pool(**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: return async_redis.BlockingConnectionPool.from_url( timeout=5, url=redis_kwargs["url"] ) 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 redis_kwargs.pop("ssl", None) redis_kwargs["connection_class"] = connection_class From 12a419864dec5a064475da7afa44bed85e7c569c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 25 Nov 2024 21:00:24 -0800 Subject: [PATCH 2/4] test_redis_with_ssl --- tests/local_testing/test_caching_ssl.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/local_testing/test_caching_ssl.py b/tests/local_testing/test_caching_ssl.py index 0825a8537..98c3335de 100644 --- a/tests/local_testing/test_caching_ssl.py +++ b/tests/local_testing/test_caching_ssl.py @@ -99,3 +99,28 @@ def 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 + pool = get_redis_connection_pool( + host=os.environ.get("REDIS_HOST"), + port=os.environ.get("REDIS_PORT"), + password=os.environ.get("REDIS_PASSWORD"), + 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") From 5aa49ad0994d8dc5922a08256bda85efcbbf1bd3 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 25 Nov 2024 21:35:13 -0800 Subject: [PATCH 3/4] test_redis_with_ssl --- tests/local_testing/test_caching_ssl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/local_testing/test_caching_ssl.py b/tests/local_testing/test_caching_ssl.py index 98c3335de..5dc4bdbbf 100644 --- a/tests/local_testing/test_caching_ssl.py +++ b/tests/local_testing/test_caching_ssl.py @@ -112,9 +112,9 @@ async def test_redis_with_ssl(): # Get the connection pool with SSL pool = get_redis_connection_pool( - host=os.environ.get("REDIS_HOST"), - port=os.environ.get("REDIS_PORT"), - password=os.environ.get("REDIS_PASSWORD"), + 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, ) From 51ad8d042594c908bff9b13017621fae5ae2a6b7 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 25 Nov 2024 21:36:00 -0800 Subject: [PATCH 4/4] test_redis_with_ssl --- tests/local_testing/test_caching_ssl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/local_testing/test_caching_ssl.py b/tests/local_testing/test_caching_ssl.py index 5dc4bdbbf..1b642f767 100644 --- a/tests/local_testing/test_caching_ssl.py +++ b/tests/local_testing/test_caching_ssl.py @@ -111,6 +111,7 @@ async def test_redis_with_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"),