Repository navigation
fix(client): use the client-side cache in clusters with a type mapping - #3556
Conversation
Codex Review SummaryThis 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. |
nkaradzhov
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the review. Done in 5555e3e: the cluster now sets |
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.
Description
Fixes #3549.
A cluster's node clients are created without the cluster's
commandOptions, so the client-side cache check in_executeCommandcompared the cluster'stypeMappingwithundefinedand skipped the cache on every command.The cluster now passes its
typeMappingto the node clients as an internalcacheTypeMappingoption, and the cache check uses it in place of the client's owncommandOptions.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 withwithTypeMapping(...)still skip the cache.The
returns Buffers from the cachetest (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
npm testpass with this change (including linting)? Ran locally (Docker, Node 24):@redis/client--grep [Cc]ache117 passing, and eslint on the changed files is clean. The cluster case ofreturns Buffers from the cachefails onmaster(Cache Misses) and passes with the fix. Full suite left to CI.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 asBuffer).Cluster node clients are created without the cluster’s full
commandOptions, so the cache gate in_executeCommandtreated every command as using a non-default type mapping and never stored hits. The cluster now injects an internalcacheTypeMappingon node clients (only when the cluster defines a mapping), and the store check compares the command’stypeMappingto 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 cachetest 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.