feat(cluster): add getNodeClientForKey for WATCH/MULTI/EXEC#3315
Merged
Conversation
Cluster client cannot expose WATCH because it needs connection-level state on a specific node. Previously users had to import cluster-key-slot, compute the slot, read cluster.slots, and call nodeClient manually. Add getNodeClientForKey(key, isReadonly?) which resolves the key's slot and returns the connected node client (master, or a slot node when readonly), enabling optimistic-locking transactions in cluster mode. Closes redis#3194 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PavelPashov
approved these changes
Jul 1, 2026
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.
Cluster client cannot expose WATCH because it needs connection-level state on a specific node. Previously users had to import cluster-key-slot, compute the slot, read cluster.slots, and call nodeClient manually.
Add getNodeClientForKey(key, isReadonly?) which resolves the key's slot and returns the connected node client (master, or a slot node when readonly), enabling optimistic-locking transactions in cluster mode.
Closes #3194
Description
Checklist
npm testpass with this change (including linting)?Note
Low Risk
Additive public API and thin routing helper on existing slot logic; no changes to default command dispatch or auth.
Overview
Adds
getNodeClientForKey(key, isReadonly?)on the cluster client so callers can run connection-scoped work (especiallyWATCH→MULTI/EXEC) on the node that owns a key’s slot, without manually usingcluster-key-slot,cluster.slots, andnodeClient.Routing matches existing cluster behavior: slot master by default, or a slot node (including replicas) when
isReadonlyistrue.docs/clustering.mddocuments the WATCH transaction pattern and the same-slot key constraint. Integration tests cover master resolution, WATCH/MULTI/EXEC, and readonly node selection.Reviewed by Cursor Bugbot for commit f3b731f. Bugbot is set up for automated code reviews on this repo. Configure here.