Skip to content

fix(client): use the client-side cache in clusters with a type mapping - #3556

Merged
nkaradzhov merged 2 commits into
redis:masterfrom
RagedPanda:fix/cluster-csc-type-mapping
Oct 30, 2026
Merged

nkaradzhov merged 2 commits into
redis:masterfrom
RagedPanda:fix/cluster-csc-type-mapping

Conversation

@RagedPanda

@RagedPanda RagedPanda commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #3549.

A cluster's node clients are created without the cluster's commandOptions, so the client-side cache check in _executeCommand compared the cluster's typeMapping with undefined and skipped the cache on every command.

The cluster now passes its typeMapping to the node clients as an internal cacheTypeMapping option, and the cache check uses it in place of the client's own commandOptions.typeMapping. The node clients still don't apply the mapping to their own replies, so slot discovery and other internal commands are unchanged. The cache still holds replies decoded with one mapping only: the cluster's. Commands sent with withTypeMapping(...) still skip the cache.

The returns Buffers from the cache test (from #3544) now also checks the cache stats (2 misses, 2 hits). Its cluster case used to pass with 0 and 0, without touching the cache.


Checklist

  • Does npm test pass with this change (including linting)? Ran locally (Docker, Node 24): @redis/client --grep [Cc]ache 117 passing, and eslint on the changed files is clean. The cluster case of returns Buffers from the cache fails on master (Cache Misses) and passes with the fix. Full suite left to CI.
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? Not needed: the new option is internal.

Note

Medium Risk
Changes client-side cache eligibility in cluster mode for mapped reply types; behavior is narrow and covered by tests, but incorrect mapping could cause wrong cached shapes or skipped caching.

Overview
Fixes #3549: client-side caching was effectively disabled on Redis Cluster when the cluster used a default commandOptions.typeMapping (e.g. BLOB strings as Buffer).

Cluster node clients are created without the cluster’s full commandOptions, so the cache gate in _executeCommand treated every command as using a non-default type mapping and never stored hits. The cluster now injects an internal cacheTypeMapping on node clients (only when the cluster defines a mapping), and the store check compares the command’s typeMapping to that value instead of the node client’s own defaults. Node clients still do not apply the cluster mapping globally, so internal topology traffic is unchanged; withTypeMapping(...) overrides still bypass the cache.

The returns Buffers from the cache test now asserts 2 misses / 2 hits so the cluster path must actually use the cache (previously it could pass with zero stats).

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T11:39:40.858276Z a990914 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, LGTM.

One optional nit: please set cacheTypeMapping only when the cluster has a typeMapping. Today the cluster always sets the key, sometimes to undefined. In plain JS, a cluster with defaults.commandOptions.typeMapping: { [RESP_TYPES.BLOB_STRING]: Buffer } and no cluster typeMapping would then start to cache, and cache hits would come back as Uint8Array instead of Buffer. TypeScript rejects that setup, so this doesn't block the merge.

@RagedPanda

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Done in 5555e3e: the cluster now sets cacheTypeMapping only when it has a typeMapping, so a node client without one falls back to its own commandOptions.typeMapping as before. The client-side cache tests (88) and cluster tests (113) pass, and eslint is clean.

@nkaradzhov
nkaradzhov merged commit e72c2a0 into redis:master Oct 30, 2026
15 checks passed
nkaradzhov pushed a commit that referenced this pull request Nov 23, 2026
A sentinel runs each command with its own commandOptions, typeMapping
included, on master and replica clients built from nodeClientOptions,
which carry no commandOptions and got no cacheTypeMapping. With a
clientSideCache and a typeMapping, every read compared the node's
undefined mapping with the sentinel's, so the cache was skipped and
every GET went to the server.

Set cacheTypeMapping from the sentinel's typeMapping when it has one,
as the cluster does for its node clients since #3556.
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.

fix(client): client-side cache is silently skipped in a cluster with commandOptions.typeMapping

2 participants