Skip to content

fix(connection): strip the cluster parameter for sync standalone clients - #867

Merged
vishal-bala merged 2 commits into
redis:mainfrom
hyeonsang010716:fix/sync-cluster-false
Nov 25, 2026
Merged

vishal-bala merged 2 commits into
redis:mainfrom
hyeonsang010716:fix/sync-cluster-false

Conversation

@hyeonsang010716

@hyeonsang010716 hyeonsang010716 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #866. RedisConnectionFactory.get_redis_connection passed cluster=False, or ?cluster=false in the URL, straight to Redis.from_url for a standalone server, so the first command raised TypeError: AbstractConnection.__init__() got an unexpected keyword argument 'cluster'. SearchIndex built with redis_url and connection_kwargs={"cluster": False} failed the same way. The async factory has stripped the parameter since #346.

Changes

Strip cluster on the sync standalone path

The standalone branch of get_redis_connection now passes the URL and kwargs through _strip_cluster_from_url_and_kwargs before Redis.from_url, as _get_aredis_connection already does. The sync cluster branch is unchanged, because RedisCluster drops cluster itself.

Remove only the cluster parameter from the URL

_strip_cluster_from_url_and_kwargs used to parse the URL and rebuild it with urlunparse. That turns unix:///tmp/redis.sock into unix:/tmp/redis.sock, which the sync client rejects with ValueError. Now that every sync standalone URL goes through the helper, it filters the query string instead. It returns the URL unchanged when there is no cluster parameter, and otherwise drops only the cluster parameters, decoding each key as parse_qs does.

Notes

The migration helpers that call Redis.from_url(redis_url) directly (redisvl/migration/planner.py:473, redisvl/migration/async_planner.py:198, redisvl/migration/quantize.py:435) are left out. They bypass the connection factory for every URL form, including cluster and sentinel URLs, so they're a separate change.

Release Notes

RedisConnectionFactory.get_redis_connection, and SearchIndex with a redis_url, now accept cluster=False or ?cluster=false for a standalone server, as the async factory already did. Before, the first command raised TypeError.

AI Assistance

  • No AI assistance was used for this PR.
  • This PR is AI-assisted. I have reviewed and understood everything in it, and I take responsibility for it.

Claude Code (claude-opus-5-5): investigation, implementation, tests and description.

Reviewer Brief

Start here: _strip_cluster_from_url_and_kwargs in redisvl/redis/connection.py:114. Every sync standalone URL now goes through it, so whatever it changes in a URL reaches every sync user.

Where it could fail

  • redisvl/redis/connection.py:132-142: the query is filtered as a string, after the fragment is split off. A URL without a cluster key must come back unchanged. With one, the other parameters must reach redis-py with the same values, and nothing in the fragment may become a parameter.

Not verified: a live unix socket server; the unix cases were checked through the connection class, path and db that redis-py parses, not by connecting. Python versions other than 3.12.

Beyond CI:

  • 3 of the 4 new test cases fail on 1d7074b. The fourth, the fragment case, passes there and fails on 1a4b519.
  • 16 URL and kwarg combinations went through both factories on 1d7074b and on this branch, on redis-py 6.3.0, 7.1.0, 7.4.1 and 8.1.0. The async clients received identical connection kwargs. The sync clients differed only by cluster no longer being passed, in the 11 cases that used to raise TypeError.
  • 29 more URL edge cases, 5 of them with & or cluster= inside a fragment, gave the async client identical connection kwargs on redis-py 8.1.0.
  • On Redis 8.4.8, CLIENT INFO showed both factories selecting db 0 for redis://…/0?cluster=false#local&db=1, as the async factory did on 1d7074b. The sync factory and SearchIndex with cluster=False or ?cluster=false raised TypeError on 1d7074b, and connect, load and query on this branch.
  • The requires_cluster tests, which CI runs only nightly, passed against a local six-node Redis 8.4 cluster on redis-py 8.1.0, 7.4.1 and 6.4.0. In some runs, 3 tests failed with "0 of 16384 slots covered" while the cluster was still forming, the same 3 on 1d7074b and on this branch.

Since the last brief: f9f71fa splits off the URL fragment before filtering the query and reattaches it unchanged.

Reviewed f9f71fa · Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs


Note

Medium Risk
Touches core connection URL parsing for every sync standalone client; incorrect query/fragment handling could misroute DB or break unix URLs, though scope is limited to stripping one parameter.

Overview
Sync standalone connections now run URLs and kwargs through _strip_cluster_from_url_and_kwargs before Redis.from_url, matching async behavior so cluster=False or ?cluster=false no longer reaches redis-py and trigger a TypeError.

The URL helper no longer rebuilds URLs with urlunparse. It strips only cluster query keys (with unquote_plus-style key decoding), leaves fragments untouched, and avoids corrupting unix:/// paths. Unit tests cover unix sockets, fragments, preserved query params, and the sync factory path.

Reviewed by Cursor Bugbot for commit f9f71fa. Bugbot is set up for automated code reviews on this repo. Configure here.

get_redis_connection passed cluster=False, or ?cluster=false in the URL,
straight to Redis.from_url, so the first command raised TypeError. The
async factory already strips it. Strip it on the sync standalone path too,
and make the helper remove only the cluster parameter: rebuilding the URL
with urlunparse turned unix:///path into unix:/path, which the sync client
rejects.
Comment thread redisvl/redis/connection.py Resolved
Splitting the URL at '?' pulled the fragment into the query, so for
redis://h/0?cluster=false#local&db=1 the helper kept db=1 as a connection
option and the client selected database 1. Split off the fragment first and
reattach it unchanged.
@vishal-bala
vishal-bala self-requested a review November 25, 2026 09:22
@vishal-bala vishal-bala added the auto:patch Increment the patch version when merged label Nov 25, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.38%. Comparing base (1d7074b) to head (f9f71fa).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #867      +/-   ##
==========================================
+ Coverage   80.17%   80.38%   +0.21%     
==========================================
  Files         121      121              
  Lines       14864    14906      +42     
  Branches     2601     2614      +13     
==========================================
+ Hits        11917    11982      +65     
+ Misses       2226     2222       -4     
+ Partials      721      702      -19     
Flag Coverage Δ
core 79.19% <100.00%> (+0.04%) ⬆️

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 merged commit d41fb72 into redis:main Nov 25, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_redis_connection raises TypeError for cluster=False on a standalone server

3 participants