Repository navigation
feat(redis): add build_async_redis_client, a synchronous async-client factory that does not warn - #874
feat(redis): add build_async_redis_client, a synchronous async-client factory that does not warn#874vishal-bala wants to merge 5 commits into
Conversation
…lient factory get_async_redis_connection warns on every call that it will become a coroutine, and said there was nothing to migrate to. Libraries that build an async client in a synchronous constructor could only pass the warning on to their users or suppress it by matching its text. build_async_redis_client builds the same client (Sentinel URLs, cluster detection and stripping of the cluster parameter, RESP2 by default, the REDIS_URL fallback, the TypeError for removed keywords), stays synchronous, and does not warn. get_async_redis_connection and _get_aredis_connection now delegate to it, so the three cannot drift, and the warning names it as the way to keep a synchronous call.
…kwargs Drop lib_name before building: only CLIENT SETINFO reports it, which the builder cannot await, and redis-py 8.1+ warns that it is deprecated when the first connection opens. Drop a cluster keyword on Sentinel URLs too, since the Sentinel pool hands it to every connection and the first command then fails. Correct the docstrings on identification (redis-py reports itself as plain redis-py) and on when cluster is stripped. Tests now fail on any DeprecationWarning raised while connecting, cover multi-host cluster detection without a cluster flag, and pin that removed keywords raise without warning.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #874 +/- ##
==========================================
+ Coverage 80.59% 80.83% +0.24%
==========================================
Files 121 121
Lines 15074 15088 +14
Branches 2643 2644 +1
==========================================
+ Hits 12149 12197 +48
+ Misses 2211 2200 -11
+ Partials 714 691 -23
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
limjoobin
left a comment
There was a problem hiding this comment.
The new builder addresses the warning-free construction use case.
Just one blocking comment - please resolve the pooled wrapper-identification concern noted inline and update the Reviewer Brief and Release Notes accordingly.
CLIENT SETINFO after the client is built labels only the connection it runs on, so connections opened later by pool growth or a reconnect reported plain redis-py and lost the wrapper's lib_name. build_async_redis_client now turns lib_name into the composed redis-py(redisvl_v...;<wrapper>) name and passes it to redis-py, which sends it on every connection it opens: as a DriverInfo on redis-py 7.2+, so 8.1 does not warn, and as lib_name on older releases. A driver_info passed by the caller is left alone.
| return | ||
| composed = make_lib_name(lib_name) | ||
| if DriverInfo is not None: | ||
| kwargs["driver_info"] = DriverInfo(name=composed) |
There was a problem hiding this comment.
This breaks async Redis Cluster client creation for users running redis-py 7.4, which is within the supported dependency range. DriverInfo is importable in that version, but AsyncRedisCluster does not accept the driver_info keyword.
For example, with redis-py 7.4.0:
RedisConnectionFactory.build_async_redis_client(
"redis://localhost:7001", cluster=True
)
# TypeError: RedisCluster.__init__() got an unexpected keyword argument 'driver_info'
This fails before connecting; the same call constructs successfully on the previous commit.
Could you choose the identity argument based on the selected client’s supported parameters, falling back to the composed lib_name for older cluster clients? Please also add an unmocked constructor test for 7.4—no running cluster is needed.
There was a problem hiding this comment.
Fixed in c11dac04. The builder now checks whether the class receiving the keywords (AsyncRedis, AsyncRedisCluster, or the connection class for Sentinel) accepts driver_info, and passes the composed lib_name otherwise, so cluster clients build on redis-py 7.2–7.4. A new unmocked test constructs standalone, cluster and Sentinel clients without a server; it raised the TypeError on 7.4.0 before the fix and passes on 7.1.0, 7.2.0, 7.4.0, 8.0.1 and 8.1.0. main is merged in (37cd5fe3), and the Reviewer Brief is updated.
There was a problem hiding this comment.
Thanks—the 7.4 cluster issue is fixed. One separate regression: the generated DriverInfo overrides explicit lib_version settings.
Repro with redis-py 8.1.0; no Redis server needed:
import warnings
from redisvl.redis.connection import RedisConnectionFactory as Factory
warnings.simplefilter("ignore", DeprecationWarning)
for version in ("custom", None):
client = Factory.get_async_redis_connection(
"redis://localhost", lib_version=version
)
print(client.connection_pool.make_connection().driver_info.lib_version)Main:
custom
None
PR:
8.1.0
8.1.0
Could you preserve the effective lib_version, including None and URL precedence, when creating DriverInfo, and add regression coverage?
…-without-deprecation-warning # Conflicts: # redisvl/redis/connection.py
redis-py 7.2 to 7.4 accept driver_info on Redis and on connections, but their async RedisCluster only takes it from 8.0, so a cluster URL raised TypeError before connecting. The builder now asks the class that will receive the keywords (AsyncRedis, AsyncRedisCluster, or the connection class for Sentinel) and falls back to the composed lib_name where driver_info is not accepted. An unmocked test constructs each client kind, verified on redis-py 7.1.0, 7.2.0, 7.4.0, 8.0.1 and 8.1.0.
limjoobin
left a comment
There was a problem hiding this comment.
Thanks for addressing the earlier findings, they’re now fixed. There’s one remaining lib_version regression noted inline; could you take a look before approval?
| return | ||
| composed = make_lib_name(lib_name) | ||
| if DriverInfo is not None: | ||
| kwargs["driver_info"] = DriverInfo(name=composed) |
There was a problem hiding this comment.
Thanks—the 7.4 cluster issue is fixed. One separate regression: the generated DriverInfo overrides explicit lib_version settings.
Repro with redis-py 8.1.0; no Redis server needed:
import warnings
from redisvl.redis.connection import RedisConnectionFactory as Factory
warnings.simplefilter("ignore", DeprecationWarning)
for version in ("custom", None):
client = Factory.get_async_redis_connection(
"redis://localhost", lib_version=version
)
print(client.connection_pool.make_connection().driver_info.lib_version)Main:
custom
None
PR:
8.1.0
8.1.0
Could you preserve the effective lib_version, including None and URL precedence, when creating DriverInfo, and add regression coverage?
Motivation
get_async_redis_connectionwarns on every call that it will become a coroutine, and offered nothing to migrate to. Libraries that build an async client in a synchronous constructor cannot await, so they either pass the warning on to users who cannot act on it (and whose suites fail underfilterwarnings = error) or suppress it by matching its text. This PR adds a supported path that does not warn and will stay synchronous.Changes
One builder, two thin wrappers
RedisConnectionFactory.build_async_redis_client(redis_url=None, **kwargs)turns a URL into anAsyncRedisorAsyncRedisClusterwithout connecting. It holds the routing that was duplicated in the two existing async factories, which now wrap it:build_async_redis_client(new)get_async_redis_connection_get_aredis_connection(internal)CLIENT SETINFOBehaviour is unchanged: Sentinel URLs, cluster detection with the
clusterparameter stripped, RESP2 by default, theREDIS_URLfallback and theTypeErrorforurl=. The warning keeps its opening words, so existing filters still match, and now names the builder.Every connection identifies itself
CLIENT SETINFOrun after the client is built labels only the connection it runs on; connections opened later by pool growth or a reconnect fall back to whatever the handshake sends. The builder therefore turnslib_nameinto the composedredis-py(redisvl_v<version>;<lib_name>)name and hands it to redis-py, which sends it on every connection it opens. It goes as aDriverInfowherever the receiving class accepts one, because 8.1 warns about thelib_namekeyword, and aslib_nameotherwise. The class is asked, not the redis-py version: 7.2 to 7.4 acceptdriver_infoonAsyncRedisand on connections but not onAsyncRedisCluster, which gains it in 8.0. A caller's owndriver_infowins.With
AsyncSearchIndex(..., lib_name="mylib_v1.0")and four concurrent commands, every connection now reportsredis-py(redisvl_v<version>;mylib_v1.0), before and after a reconnect.A
clusterkeyword on a Sentinel URL is now dropped, because every pooled connection received it and the first command failed with aTypeError.Notes
Clients from
get_async_redis_connectionnow report the composed RedisVL name on every connection, where they previously reported the rawlib_name, orredis-pywithout one. The sync factory still labels only one connection; it is unchanged here.get_async_redis_cluster_connectionis already synchronous and silent, and is left as it is; whether it stays synchronous at the next major release is for the maintainers to decide.A warning subclass or a once-per-process warning would still warn, and a public awaitable cannot be called from a constructor, so neither meets the need.
Migration notes for dependents
To support older RedisVL, pick the builder with
getattr(RedisConnectionFactory, "build_async_redis_client", None)and keep the current suppression as the fallback until the floor moves.Release Notes
RedisConnectionFactory.build_async_redis_clientbuilds an async Redis client from a URL without theDeprecationWarningthatget_async_redis_connectionemits, and will stay synchronous. Every connection of an async client built from a URL, including those fromget_async_redis_connectionandAsyncSearchIndex, now reportsredis-py(redisvl_v<version>;<lib_name>)to the server, without redis-py'slib_namedeprecation warning.Reviewer Brief
Start here:
build_async_redis_clientinredisvl/redis/connection.py. Every async client RedisVL builds from a URL now goes through it.Where it could fail
_set_handshake_identityand_accepts_driver_info: the keyword is chosen by inspecting the receiving class's signature (AsyncRedis,AsyncRedisCluster, or the connection class for Sentinel); a redis-py release that acceptsdriver_infoonly through**kwargswould getlib_nameinstead, which still works.cluster; the sync twinget_redis_connectionstill forwards it, unchanged here.Not verified: a live Sentinel (mocked unit tests only); the
requires_clustertest, skipped without a cluster; the full suite on redis-py other than 8.1.0 (only the builder tests ran on the other versions).Beyond CI: the unmocked constructor test raises
TypeErrorfor the cluster client on redis-py 7.4.0 beforec11dac04and passes after; the builder tests pass on redis-py 7.1.0, 7.2.0, 7.4.0, 8.0.1 and 8.1.0; the full suite passed locally on Python 3.15 againstredis:8.4(3293 passed, 147 skipped).Since the last brief:
2a5c4f2dsends the composed name through the connection handshake, so pooled and reconnected connections keep the wrapper name;c11dac04choosesdriver_infoorlib_nameper client class, so async cluster clients build on redis-py 7.2 to 7.4;37cd5fe3mergesmain.Reviewed
d24df647, fixes inb314fe0b,2a5c4f2d,c11dac04· Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs, Redis behaviour