redis/node-redis · error · Error
empty keyValuePairs Argument
Error message
empty keyValuePairs Argument
What it means
Thrown by parseMSetExArguments when the keyValuePairs argument passed to MSETEX is an Array with length 0. MSETEX needs at least one key/value pair (plus optional mode/expiration); an empty payload is rejected client-side before the command is sent.
Source
Thrown at packages/client/lib/commands/MSETEX.ts:62
type SetConditionOption = typeof SetMode.XX | typeof SetMode.NX;
type ExpirationOption =
| { type: typeof ExpirationMode.EX; value: number }
| { type: typeof ExpirationMode.PX; value: number }
| { type: typeof ExpirationMode.EXAT; value: number | Date }
| { type: typeof ExpirationMode.PXAT; value: number | Date }
| { type: typeof ExpirationMode.KEEPTTL };
export function parseMSetExArguments(
parser: CommandParser,
keyValuePairs: MSetArguments
) {
let tuples: Array<[RedisArgument, RedisArgument]> = [];
if (Array.isArray(keyValuePairs)) {
if (keyValuePairs.length == 0) {
throw new Error("empty keyValuePairs Argument");
}
if (Array.isArray(keyValuePairs[0])) {
tuples = keyValuePairs as Array<[RedisArgument, RedisArgument]>;
} else {
const arr = keyValuePairs as Array<RedisArgument>;
for (let i = 0; i < arr.length; i += 2) {
tuples.push([arr[i], arr[i + 1]]);
}
}
} else {
for (const tuple of Object.entries(keyValuePairs)) {
tuples.push([tuple[0], tuple[1]]);
}
}
// Push the number of keys
parser.push(tuples.length.toString());
View on GitHub (pinned to bb5beb5657)
Solutions
- Skip the MSETEX call when the array is empty.
- Validate the payload has at least one pair before invoking.
- Build pairs from a guaranteed non-empty source.
Example fix
// before
await client.msetEx(pairs, { mode: 'NX' }); // pairs may be []
// after
if (pairs.length > 0) await client.msetEx(pairs, { mode: 'NX' }); Defensive patterns
Strategy: validation
Validate before calling
function nonEmptyMSetEx(a) { if (Array.isArray(a) && a.length === 0) throw new Error('MSETEX needs >=1 pair'); }
nonEmptyMSetEx(pairs); await client.msetEx(pairs, opts); Type guard
function hasMSetExPairs(a) { return Array.isArray(a) ? a.length > 0 : a != null && Object.keys(a).length > 0; } Try / catch
if (hasMSetExPairs(pairs)) await client.msetEx(pairs, opts);
Prevention
- Guard batch writes for emptiness before calling MSETEX.
- Filter to pairs and assert non-empty.
- Unit-test the empty-input path of write helpers.
When it happens
Trigger: Calling client.msetEx([]) or passing an empty array built from a filtered/empty source.
Common situations: Bulk-write helper invoked with no pending entries; conditional flush of an empty change set; refactor that drops the empty check.
Related errors
- empty toSet Argument
- "arguments[${i}]" must be of type "string | Buffer", got ${t
- expirationRefreshRatio must be less than or equal to 1
- expirationRefreshRatio must be greater or equal to 0
- All statistics values must be non-negative
AI-assisted analysis of redis/node-redis@bb5beb5657 (2026-08-03).
Data as JSON: /data/errors/e0842b844a723058.json.
Report an issue: GitHub.