fix(client): MEMORY USAGE must emit SAMPLES when 0#3328
Merged
nkaradzhov merged 1 commit intoJul 10, 2026
Conversation
`MEMORY USAGE key SAMPLES 0` was guarded by a truthy check (`if (options?.SAMPLES)`), so an explicit `0` was silently dropped and the command fell back to the server default of 5 samples. Per the Redis docs, `SAMPLES 0` samples all nested values (an exact size) instead of estimating from 5, so the two are observably different for aggregate types. Guard on `!== undefined` so `0` is forwarded, matching the recent RESTORE IDLETIME/FREQ 0 fix (redis#3323). Adds a `SAMPLES 0` argument test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nkaradzhov
approved these changes
Jul 10, 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.
Description
MEMORY USAGE key SAMPLES 0was being dropped. TheSAMPLESoption is guarded by a truthy check:so an explicit
0is falsy and never emitted — the command silently degrades toMEMORY USAGE key, which uses the server default of 5 samples.Per the Redis docs:
So
SAMPLES 0means "scan all nested values" (an exact size) rather than estimating from 5 — observably different for aggregate types (lists/hashes/sets/zsets). Dropping it changes the returned size.Fix: guard on
!== undefinedso an explicit0is forwarded. This mirrors the recent same-class fix forRESTORE IDLETIME/FREQ 0(#3323) andXSETID ENTRIESADDED 0(#3324).Added a
transformArgumentstest forSAMPLES: 0.Checklist
npm testpass with this change (including linting)? — theMEMORY USAGEspec passes (4 tests incl. the new case) andeslintis clean on the changed files.SAMPLES 0argument test; it fails on the old truthy guard and passes with!== undefined.SAMPLES?: numberoption); added a JSDoc note documenting the0semantics.Drafted with AI assistance (Claude); reviewed and verified by me. Every line is mine to defend.
Note
Low Risk
Small read-only command argument parsing fix with a regression test; no auth, data mutation, or broad API surface change.
Overview
Fixes
MEMORY USAGEso an explicitSAMPLES: 0is sent to Redis instead of being dropped. The parser used a truthy check onSAMPLES, so0never producedSAMPLES 0and the command fell back to the server default (5 samples), which changes memory estimates for aggregate keys.The guard is now
options?.SAMPLES !== undefined, matching the pattern used for other numeric options that allow0.MemoryUsageOptionsgets a short JSDoc note that0means sample all nested values, and atransformArgumentstest asserts['MEMORY', 'USAGE', 'key', 'SAMPLES', '0'].Reviewed by Cursor Bugbot for commit ff8b0c4. Bugbot is set up for automated code reviews on this repo. Configure here.