Repository navigation
Conversation
sync_to_async_redis passed the sync pool's connection_kwargs straight to the async pool and picked the TLS class with an exact-type check, so a client built with Redis(ssl=True, ...), Redis(unix_socket_path=...) or Sentinel.master_for(...) raised TypeError on its first async command, and a subclass of SSLConnection got a plaintext async connection. The async connection class is now chosen with issubclass for TLS and unix-socket connections, keywords the async class does not accept are dropped when they hold their default, a sync-only setting that is set (such as OCSP validation) raises a clear ValueError instead of being lost, and Sentinel-managed pools are rejected up front like RedisCluster. Closes redis#789
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #789.
Motivation
RedisConnectionFactory.sync_to_async_redispassed the sync pool'sconnection_kwargsstraight intoAsyncConnectionPooland picked the TLS class with an exact-type check. A client built withRedis(ssl=True, ...),Redis(unix_socket_path=...)orSentinel.master_for(...)therefore raisedTypeErroron its first async command (SemanticCache.acheck, andSemanticRouter.arouteonce #784 lands), and a subclass ofSSLConnectiongot a plaintext async connection with the password still set.Changes
issubclass: TLS connections (and subclasses) map toAsyncSSLConnection, unix-socket connections to the asyncUnixDomainSocketConnection, everything else toAsyncConnection._async_connection_kwargskeeps only the keywords the chosen async class accepts, found by walking its__init__chain (_accepted_init_kwargs), so the filter follows whatever redis-py version is installed rather than a hard-coded key list. A sync-only keyword at its default (NoneorFalse) is dropped; one that is set, such asssl_validate_ocsp=True, raises aValueErrornaming it, because the async client cannot honour it and dropping it would silently weaken TLS verification.ValueError, asRedisClusteralready was.tests/unit/test_sync_to_async_redis.py, none needing a server; five fail onmain.Release Notes
SemanticCache,AsyncSearchIndexand any other async path that converts a caller's sync client now work with clients configured with TLS keywords (Redis(ssl=True, ...)), unix sockets, and customSSLConnectionsubclasses. Sentinel-managed clients,RedisClusterclients, and clients with a sync-only setting enabled (OCSP validation) raiseValueErrorat conversion time with a pointer toredis_url; previously they failed withTypeErroron the first command.Reviewer Brief
Start here:
redisvl/redis/connection.py,_async_connection_kwargs. It decides which of the sync pool's settings reach the async connection and which abort the conversion;sync_to_async_redisonly picks the class and calls it.Where it could fail
redisvl/redis/connection.py:350: a sync-only keyword whose default is notNoneorFalse(none exist in redis-py 6.3.0 through 8.1.0) would make every conversion raise; check thevalue not in (None, False)test against any new keyword a future redis-py adds.redisvl/redis/connection.py:328:_accepted_init_kwargsstops at the first__init__without**kwargs; if redis-py ever adds keywords belowAbstractConnectionin the chain they would be dropped as unaccepted.Not verified: cluster mode (unchanged path, raises as before); a live TLS or unix-socket server (the tests stop at
make_connection(), where every reported failure occurred).Beyond CI: the seven new tests pass on redis-py 8.1.0 and on 6.3.0, the floor in
pyproject.toml; five of them fail onmain.tests/integration/test_llmcache.py,test_embedcache.pyandtest_async_search_index.py: 140 passed (Redis 8.4 via the repo's testcontainers compose);tests/unit: 1823 passed.Reviewed
d23003e· Claude Code (claude-fable-5-1) · lenses: correctness, security, design, tests, docsNotes
AsyncSentinel, as the issue suggests. The pool does carrysentinel_managerandservice_name, so a later change could rebuild it; that is a separate feature.SemanticRouterdocstring reduces to Sentinel and cluster; I'll trim it there.🤖 Generated with Claude Code
Note
Medium Risk
Touches connection/TLS conversion used by async cache and index paths; incorrect kwarg handling could weaken TLS or break conversion, though sync-only enabled options now fail loudly instead of silently.
Overview
RedisConnectionFactory.sync_to_async_redisnow builds async clients from sync pool settings instead of blindly copyingconnection_kwargsand using an exactSSLConnectiontype check.Connection class selection uses
issubclass: TLS (including customSSLConnectionsubclasses) →AsyncSSLConnection, unix sockets →AsyncUnixDomainSocketConnection, otherwiseAsyncConnection._async_connection_kwargsfilters kwargs by introspecting the async connection class’s__init__chain; sync-only keys at default (None/False) are dropped, but non-default sync-only settings (e.g.ssl_validate_ocsp=True) raiseValueErrorso TLS options are not silently weakened. Sentinel-managed pools are rejected up front with a clear error, likeRedisCluster.Seven unit tests cover plain/TLS/URL/unix/Sentinel/OCSP cases without a live Redis server.
Reviewed by Cursor Bugbot for commit d23003e. Bugbot is set up for automated code reviews on this repo. Configure here.