Skip to content

fix(tools): make scan_all_keys work in cluster mode - #212

Merged
vchomakov merged 1 commit into
redis:mainfrom
pcbeingused333:fix/scan-all-keys-cluster
Nov 29, 2026
Merged

vchomakov merged 1 commit into
redis:mainfrom
pcbeingused333:fix/scan-all-keys-cluster

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

With REDIS_CLUSTER_MODE enabled, scan_all_keys always returns an error instead of the matching keys:

Error scanning all keys with pattern 'user:*': Invalid input of type: 'dict'. Convert to a bytes, string, int or float first.

Cause: RedisCluster.scan returns a dict of per-node cursors rather than a single integer. The cursor == 0 check never matches, and the dict is passed back as the next cursor.

Fix: use r.scan_iter(match=..., count=...), which redis-py implements for both standalone and cluster clients and which tracks each node's cursor. Byte decoding is unchanged.

Verification: on a local 3-node cluster with 500 user:* keys and batch_size=50, main returns the error above and this branch returns all 500 keys. The new test runs redis-py's own cluster scan_iter over a mocked SCAN; it fails on main and passes here. The full test suite passes (389 tests), and ruff check/format are clean.

Not changed: scan_keys also exposes the per-node cursor dict in cluster mode. Fixing it means deciding how a cluster cursor should look in the tool's interface, so it is left out of this PR.

This change was prepared with AI assistance (Claude Code).

RedisCluster.scan returns a dict of per-node cursors, so the cursor == 0
check never matched and the dict was sent back as the next cursor. Use
scan_iter, which handles both standalone and cluster cursors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (faeb09f) to head (581a326).
⚠️ Report is 65 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #212      +/-   ##
==========================================
+ Coverage   88.20%   88.53%   +0.32%     
==========================================
  Files          19       19              
  Lines        1060     1116      +56     
==========================================
+ Hits          935      988      +53     
- Misses        125      128       +3     
Flag Coverage Δ
unittests 88.53% <100.00%> (+0.32%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@vchomakov vchomakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, verified locally on a 6-node cluster (3 primaries, 3 replicas) and a standalone Redis.
LGTM.

@vchomakov
vchomakov merged commit c039071 into redis:main Nov 29, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants