redis/node-redis · error · Error

empty toSet Argument

Error message

empty toSet Argument

What it means

parseMSetArguments rejects an empty array argument for MSET. MSET requires at least one key-value pair; an empty array means there is nothing to set and the server would reject the command anyway with a wrong number of arguments error.

Solutions

  1. Guard the call with a length check: if (entries.length > 0) await client.mSet(entries)
  2. Skip the MSET call entirely when the collection is empty
  3. Use Object.keys(obj).length > 0 before calling mSet with a Record

Example fix

// before
await client.mSet(pairs);
// after
if (pairs.length > 0) {
  await client.mSet(pairs);
}
Defensive patterns

Strategy: validation

Validate before calling

// Guard against empty collections before calling mSet.
function hasEntries(data: Array<[string, string]> | Array<string> | Record<string, string>): boolean {
  if (Array.isArray(data)) return data.length > 0;
  return Object.keys(data).length > 0;
}

if (hasEntries(pairs)) {
  await client.mSet(pairs);
}

Type guard

function isNonEmptyArray<T>(arr: T[]): arr is [T, ...T[]] {
  return arr.length > 0;
}

Prevention

When it happens

Trigger: Calling client.mSet([]) with an empty flat array, client.mSet([[]]) with an empty tuple array, or passing an empty Record object that Object.entries turns into zero pairs.

Common situations: Dynamically building the key-value map from a data source that returned no results; conditional logic that produces an empty collection; batching logic that occasionally produces zero entries.

Related errors


AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11). Data as JSON: /api/errors/4a2cf30661bbeae8. Report an issue: GitHub.

Appendix: 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 90fd0652bc)