redis/node-redis · error · Error

empty toSet Argument

Error message

empty toSet Argument

What it means

Thrown by parseMSetArguments when the toSet argument passed to MSET is an Array with length 0. MSET requires at least one key/value pair; an empty array has nothing to send and the client rejects it before issuing the command.

Source

Thrown at packages/client/lib/commands/MSET.ts:12

import { CommandParser } from '../client/parser';
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';

export type MSetArguments =
  Array<[RedisArgument, RedisArgument]> |
  Array<RedisArgument> |
  Record<string, RedisArgument>;

export function parseMSetArguments(parser: CommandParser, toSet: MSetArguments) {
  if (Array.isArray(toSet)) {
    if (toSet.length == 0) {
      throw new Error("empty toSet Argument")
    }
    if (Array.isArray(toSet[0])) {
      for (const tuple of (toSet as Array<[RedisArgument, RedisArgument]>)) {
        parser.pushKey(tuple[0]);
        parser.push(tuple[1]);
      }
    } else {
      const arr = toSet as Array<RedisArgument>;
      for (let i=0; i < arr.length; i += 2) {
        parser.pushKey(arr[i]);
        parser.push(arr[i+1]);
      }
    }
  } else {
    for (const tuple of Object.entries(toSet)) {
      parser.pushKey(tuple[0]);
      parser.push(tuple[1]);
    }

View on GitHub (pinned to bb5beb5657)

Solutions

  1. Guard the call: skip MSET entirely when the array is empty.
  2. Ensure at least one key/value pair is present before calling.
  3. If building from entries, filter to pairs and assert non-empty.

Example fix

// before
await client.mSet(entries); // entries may be []

// after
if (entries.length > 0) await client.mSet(entries);
Defensive patterns

Strategy: validation

Validate before calling

function nonEmptyKv(a) { if (Array.isArray(a) && a.length === 0) throw new Error('mSet needs >=1 pair'); }
nonEmptyKv(toSet); await client.mSet(toSet);

Type guard

function hasMSetPairs(a) { return Array.isArray(a) ? a.length > 0 : a != null && Object.keys(a).length > 0; }

Try / catch

if (hasMSetPairs(toSet)) await client.mSet(toSet);

Prevention

When it happens

Trigger: Calling client.mset([]) or client.mSet([]). Also reachable when a dynamically-built array of key/value tuples is empty because upstream filtering removed all entries.

Common situations: Batch-building an MSET payload from a source that can be empty (e.g. flushing buffered writes when the buffer happens to be empty); refactoring that leaves a placeholder empty array.

Related errors


AI-assisted analysis of redis/node-redis@bb5beb5657 (2026-08-03). Data as JSON: /data/errors/4a2cf30661bbeae8.json. Report an issue: GitHub.