Skip to content

fix(command): serialize large integer arguments in decimal notation - #2136

Merged
PavelPashov merged 1 commit into
redis:mainfrom
spokodev:fix/large-integer-arg-serialization
Jul 9, 2026
Merged

PavelPashov merged 1 commit into
redis:mainfrom
spokodev:fix/large-integer-arg-serialization

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Numeric command arguments are stringified with String(). For integers >= 1e21, String() produces exponential notation, which is written verbatim to the wire:

new Command("set", ["key", 10 ** 21]).args; // ["key", "1e+21"]

Redis stores the literal 1e+21 and rejects it for integer commands (PEXPIRE, PSETEX, INCR, SET … PX, …) with ERR value is not an integer or out of range. Even exactly-representable integers are affected: 2 ** 70 serializes to "1.1805916207174113e+21" instead of "1180591620717411303424".

In toArg, integer-valued numbers outside the safe-integer range are converted with BigInt, yielding the full decimal string. Safe integers, floats, strings and buffers are untouched. Adds a unit test asserting the serialized argument bytes.


Note

Low Risk
Narrow change to argument stringification for unsafe integers only, with a targeted unit test and no auth or data-path redesign.

Overview
Fixes Redis wire serialization for numeric command arguments that exceed JavaScript’s safe integer range.

toArg now detects integer number values where !Number.isSafeInteger(arg) and stringifies them via BigInt(arg).toString() instead of String(arg). That avoids exponential forms like 1e+21 on the RESP payload, which Redis treats as invalid for integer-oriented commands (PEXPIRE, INCR, SET with PX, etc.). Safe integers, floats, strings, and buffers still follow the existing String() path.

A unit test on Command asserts both normalized args and toWritable() output for 10 ** 21.

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

Numeric command arguments are stringified with String(), which renders
integers >= 1e21 in exponential notation (e.g. String(10 ** 21) yields
"1e+21"). That form is written verbatim to the wire, so Redis stores a
corrupted value and rejects it for integer commands such as PEXPIRE,
PSETEX, INCR or SET ... PX with "value is not an integer or out of range".

Convert integer-valued numbers outside the safe-integer range with BigInt
so they are emitted as full decimal strings. Safe integers, floats,
strings and buffers keep their existing serialization.

@PavelPashov PavelPashov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution

@PavelPashov
PavelPashov merged commit 09b8d04 into redis:main Jul 9, 2026
18 checks passed
github-actions Bot pushed a commit that referenced this pull request Jul 29, 2026
# [6.0.0-beta.1](v5.11.1...v6.0.0-beta.1) (2026-07-29)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions Bot pushed a commit that referenced this pull request Jul 31, 2026
# [6.0.0](v5.11.1...v6.0.0) (2026-07-31)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))
* **types:** export ScanStreamOptions, RedisStatus and ClusterStatus ([#2158](#2158)) ([cf3bf71](cf3bf71))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* himport managed fieldsets ([#2159](#2159)) ([729f174](729f174))
* improve default connection resilience ([#2160](#2160)) ([6d0716e](6d0716e))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants