Skip to content

feat(redis): add build_async_redis_client, a synchronous async-client factory that does not warn - #874

Open
vishal-bala wants to merge 5 commits into
mainfrom
feat/async-connection-without-deprecation-warning
Open

vishal-bala wants to merge 5 commits into
mainfrom
feat/async-connection-without-deprecation-warning

Conversation

@vishal-bala

@vishal-bala vishal-bala commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

get_async_redis_connection warns 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 under filterwarnings = 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 an AsyncRedis or AsyncRedisCluster without connecting. It holds the routing that was duplicated in the two existing async factories, which now wrap it:

Function Does Awaited Warns
build_async_redis_client (new) Build the client No, and stays so No
get_async_redis_connection Build No, until the next major release Yes
_get_aredis_connection (internal) Build, then CLIENT SETINFO Yes No

Behaviour is unchanged: Sentinel URLs, cluster detection with the cluster parameter stripped, RESP2 by default, the REDIS_URL fallback and the TypeError for url=. The warning keeps its opening words, so existing filters still match, and now names the builder.

Every connection identifies itself

CLIENT SETINFO run 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 turns lib_name into the composed redis-py(redisvl_v<version>;<lib_name>) name and hands it to redis-py, which sends it on every connection it opens. It goes as a DriverInfo wherever the receiving class accepts one, because 8.1 warns about the lib_name keyword, and as lib_name otherwise. The class is asked, not the redis-py version: 7.2 to 7.4 accept driver_info on AsyncRedis and on connections but not on AsyncRedisCluster, which gains it in 8.0. A caller's own driver_info wins.

With AsyncSearchIndex(..., lib_name="mylib_v1.0") and four concurrent commands, every connection now reports redis-py(redisvl_v<version>;mylib_v1.0), before and after a reconnect.

A cluster keyword on a Sentinel URL is now dropped, because every pooled connection received it and the first command failed with a TypeError.

Notes

Clients from get_async_redis_connection now report the composed RedisVL name on every connection, where they previously reported the raw lib_name, or redis-py without one. The sync factory still labels only one connection; it is unchanged here.

get_async_redis_cluster_connection is 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

# Before: warns, and will need awaiting after the next major release
client = RedisConnectionFactory.get_async_redis_connection(redis_url, **kwargs)

# After: same client, silent, stays synchronous
client = RedisConnectionFactory.build_async_redis_client(redis_url, lib_name="mylib_v1.2", **kwargs)

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_client builds an async Redis client from a URL without the DeprecationWarning that get_async_redis_connection emits, and will stay synchronous. Every connection of an async client built from a URL, including those from get_async_redis_connection and AsyncSearchIndex, now reports redis-py(redisvl_v<version>;<lib_name>) to the server, without redis-py's lib_name deprecation warning.

Reviewer Brief

Start here: build_async_redis_client in redisvl/redis/connection.py. Every async client RedisVL builds from a URL now goes through it.

Where it could fail

  • _set_handshake_identity and _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 accepts driver_info only through **kwargs would get lib_name instead, which still works.
  • The Sentinel branch now drops cluster; the sync twin get_redis_connection still forwards it, unchanged here.

Not verified: a live Sentinel (mocked unit tests only); the requires_cluster test, 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 TypeError for the cluster client on redis-py 7.4.0 before c11dac04 and 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 against redis:8.4 (3293 passed, 147 skipped).

Since the last brief: 2a5c4f2d sends the composed name through the connection handshake, so pooled and reconnected connections keep the wrapper name; c11dac04 chooses driver_info or lib_name per client class, so async cluster clients build on redis-py 7.2 to 7.4; 37cd5fe3 merges main.

Reviewed d24df647, fixes in b314fe0b, 2a5c4f2d, c11dac04 · Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs, Redis behaviour

…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-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.83%. Comparing base (d9f4193) to head (c11dac0).

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     
Flag Coverage Δ
core 79.93% <100.00%> (+0.13%) ⬆️
service 80.35% <87.09%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vishal-bala
vishal-bala marked this pull request as ready for review December 2, 2026 09:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T09:38:58.847112Z b314fe0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@vishal-bala vishal-bala added auto:minor Increment the minor version when merged auto:internal Changes only affect the internal API and removed auto:minor Increment the minor version when merged auto:internal Changes only affect the internal API labels Dec 2, 2026

@limjoobin limjoobin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread redisvl/redis/connection.py Resolved
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.
@vishal-bala
vishal-bala requested a review from limjoobin December 2, 2026 14:24

@limjoobin limjoobin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one more issue + the merge conflict to resolve and we should be good to go!

return
composed = make_lib_name(lib_name)
if DriverInfo is not None:
kwargs["driver_info"] = DriverInfo(name=composed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@vishal-bala
vishal-bala requested a review from limjoobin December 4, 2026 09:25

@limjoobin limjoobin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:minor Increment the minor version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants