fix(client): XADD/XTRIM with LIMIT 0 must emit the argument#3342
Merged
Conversation
`XADD ... TRIM.limit` and `XTRIM ... LIMIT` were guarded by a truthy check (`if (options.TRIM.limit)` / `if (options?.LIMIT)`), so an explicit `0` was silently dropped and the server fell back to its implicit default limit. Per the Redis docs, `LIMIT 0` means unlimited trimming, whereas omitting LIMIT caps eviction at `100 * stream-node-max-entries` (10000 by default), so the two are observably different. Against Redis 8.8, trimming a 20000-entry stream with `MAXLEN ~ 1` evicts 10000 entries without LIMIT but 19900 with `LIMIT 0` — meaning a caller asking for unlimited trimming currently gets the capped default instead. Guard on `!== undefined` so `0` is forwarded, matching the recent XGROUP ENTRIESREAD 0 fix (redis#3333). Adds a `LIMIT 0` argument test for both commands. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nkaradzhov
approved these changes
Jul 16, 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
XTRIM ... LIMITandXADD ... TRIM.limitare guarded by a truthy check, so passing an explicit0drops the argument entirely:That matters because
LIMIT 0and omitting LIMIT are not the same thing.LIMIT 0means unlimited trimming, while omitting it caps eviction at100 * stream-node-max-entries(10000 with the defaults). So today a caller who explicitly asks for unlimited trimming silently gets the capped default instead.I checked this against Redis 8.8 with a 20000-entry stream, trimming with
MAXLEN ~ 1:{ LIMIT: 0 }(before)XTRIM key MAXLEN ~ 1{ LIMIT: 0 }(after)XTRIM key MAXLEN ~ 1 LIMIT 0The fix is to guard on
!== undefinedso0is forwarded, same as the recentXGROUP ... ENTRIESREAD 0fix in #3333. BothXTRIMandXADD'sTRIM.limitare affected, so I fixed both and added aLIMIT 0argument test for each.Checklist
npm testpass with this change (including linting)?One caveat on the first box: I don't have Docker on this machine, so I couldn't run the full suite locally — the integration tests spin up containers. I ran the
transformArgumentsassertions directly and verified the end-to-end behaviour against a local Redis 8.8 server (the table above). Happy to adjust if CI turns up anything.No docs change — this restores the documented behaviour rather than changing the API.
Note
Low Risk
Small, localized fix to command serialization with matching unit tests; behavior change only when callers pass
0, aligning with documented Redis semantics.Overview
XADD (
TRIM.limit) and XTRIM (LIMIT) now include theLIMITclause when the value is0, by checking!== undefinedinstead of a truthy guard.Previously,
LIMIT: 0was dropped from the wire protocol, so Redis treated the call as “no LIMIT” (default eviction cap) rather than unlimited trimming perLIMIT 0. Unit tests assert the serialized argv forlimit/LIMITof0.Reviewed by Cursor Bugbot for commit 63fe547. Bugbot is set up for automated code reviews on this repo. Configure here.