You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normalize Redis connection handling and CLI URL resolution (#576)
# Summary
This PR makes Redis connection behavior more consistent across the SDK
and CLI. It fixes cases where different surfaces created Redis clients
differently, dropped connection kwargs, or treated internally-created
clients as externally owned.
On the SDK side, `from_existing()` paths for `SearchIndex`,
`AsyncSearchIndex`, and `SemanticRouter` now consistently prefer a
caller-provided client, preserve normalized connection kwargs, and
correctly mark internally-created clients as owned so disconnect
behavior works as expected. The shared kwargs splitting used by these
entry points is now centralized in `redisvl/redis/connection.py` so
internal _-prefixed kwargs do not leak into Redis
client construction.
This PR also routes more connection creation through
`RedisConnectionFactory` instead of ad hoc client creation. That
includes cache and SQL helper paths, and it fixes several extension
surfaces that were passing connection kwargs incorrectly into
SearchIndex.
On the CLI side, Redis URL resolution is simplified and made more
predictable. The helper now cleanly resolves between explicit `--url`,
explicit connection flags, `REDIS_URL`, and the local default, while
also avoiding malformed URL assembly and accidental empty-auth behavior.
The CLI entrypoints were simplified accordingly.
The net effect is a smaller and more uniform connection model: explicit
clients are respected, factory-based connection behavior is reused
across surfaces, reconnect/disconnect semantics are correct, and the CLI
no longer has several connection-resolution edge cases that previously
produced the wrong URL.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches core connection creation/ownership paths across `SearchIndex`,
caches, routers, and CLI URL parsing; behavior changes could affect how
clients are constructed and when connections are closed.
>
> **Overview**
> **Normalizes Redis connection behavior across the SDK and CLI.** CLI
commands now resolve Redis endpoints deterministically (explicit `--url`
> explicit flags > `REDIS_URL` > localhost defaults), properly
URL-encode auth, and only override env URLs with SSL via scheme
rewriting.
>
> **Unifies client creation and ownership semantics.**
`SearchIndex.from_existing`/`AsyncSearchIndex.from_existing` and
`SemanticRouter.from_existing` now prefer caller-provided clients,
split/forward only connection kwargs to `RedisConnectionFactory`, track
whether internally-created clients are owned (so `disconnect()` closes
them), and ensure temporary clients are closed on load failures. Several
extensions (`SemanticCache`, message histories, router init) now pass
`connection_kwargs` explicitly (instead of splatting), and SQL query
helper/client creation is routed through `RedisConnectionFactory`.
>
> Adds unit tests covering CLI URL precedence/encoding and connection
normalization (client preference, kwargs forwarding, and
ownership/cleanup).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
517d281. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
0 commit comments