Repository navigation
fix(cluster): route the empty-string key by slot instead of at random - #3660
Merged
nkaradzhov merged 1 commit intoNov 23, 2026
Merged
Conversation
getClientAndSlotNumber treated the first key as keyless with a falsy
check (!firstKey), but the empty string is a valid Redis key (slot 0).
So commands like cluster.set('', v) or cluster.get('') were sent to a
random node instead of the slot owner, producing a MOVED loop — and a
MaxCommandRedirectionsError once the cluster has more than
maxCommandRedirections nodes.
Match the pinned-client path and the parser's own checks by routing as
keyless only when firstKey === undefined. An empty Buffer was already
routed correctly (a Buffer is truthy); this fixes the empty string.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getClientAndSlotNumberclassified the routing key as keyless with a falsy check (!firstKey), but the empty string is a valid Redis key (slot 0). Socluster.set('', v)/cluster.get('')were sent to a random node instead of the slot owner — aMOVEDloop, and aMaxCommandRedirectionsErroronce the cluster has more thanmaxCommandRedirectionsnodes.The pinned-client path (
index.ts) and the parser already gate onfirstKey === undefined; this aligns the normal routing path with them. An empty Buffer was already routed correctly (a Buffer is truthy) — this only affects the empty string.Added a unit test (in-process fake node, no docker) asserting
""resolves its slot rather than taking the keyless random-node branch.Note
Medium Risk
Touches core cluster command routing; the change is small but incorrect routing could still affect any caller using empty-string keys until deployed.
Overview
Fixes cluster routing so
""is treated as a keyed command (hash slot 0) instead of being sent to a random node like true keyless commands.In
getClientAndSlotNumber, the keyless branch now checksfirstKey === undefinedinstead of!firstKey, matching the pinned-client path and parser. That stops operations likecluster.set('', v)/cluster.get('')from missing the slot owner and hittingMOVEDloops orMaxCommandRedirectionsErroron larger clusters.Adds an in-process unit test with a fake RESP2 node asserting
""returns slot 0 and the slot owner client, whileundefinedstill routes keylessly with no slot.Reviewed by Cursor Bugbot for commit 1277b60. Bugbot is set up for automated code reviews on this repo. Configure here.