Skip to content

feat(cluster): add getNodeClientForKey for WATCH/MULTI/EXEC#3315

Merged
nkaradzhov merged 1 commit into
redis:masterfrom
nkaradzhov:cluster-node-watch
Jul 1, 2026
Merged

feat(cluster): add getNodeClientForKey for WATCH/MULTI/EXEC#3315
nkaradzhov merged 1 commit into
redis:masterfrom
nkaradzhov:cluster-node-watch

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

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

Describe your pull request here


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

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 (especially WATCHMULTI/EXEC) on the node that owns a key’s slot, without manually using cluster-key-slot, cluster.slots, and nodeClient.

Routing matches existing cluster behavior: slot master by default, or a slot node (including replicas) when isReadonly is true. docs/clustering.md documents 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.

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>
@nkaradzhov nkaradzhov requested a review from PavelPashov June 25, 2026 11:16
@nkaradzhov nkaradzhov merged commit a476aa6 into redis:master Jul 1, 2026
14 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.

Provide public API for getting node-specific client for WATCH/MULTI/EXEC in cluster mode

2 participants