redis/redis-py · error · RedisClusterException

No way to dispatch this command to Redis Cluster. Missing…

Error message

No way to dispatch this command to Redis Cluster. Missing key.
You can execute the command by specifying target nodes.
Command: {args}

What it means

Raised as a RedisClusterException by determine_slot() when the command's keys cannot be determined (the key parser returns None or an empty list) and the command is not FCALL/FCALL_RO (which legitimately can have zero keys). Without keys, the cluster router cannot compute a hash slot to target a specific node. The error message tells you to specify target nodes explicitly instead.

Solutions

  1. Pass an explicit target_nodes argument, e.g. client.execute_command('INFO', target_nodes='PRIMARIES') or target_nodes='ALL_NODES'.
  2. For commands that affect all nodes, use the nodes_flag constants PRIMARIES, REPLICAS, ALL_NODES, or RANDOM.
  3. If the command should have keys, verify the command name is recognized by Redis COMMAND INFO so the key parser can extract them.

Example fix

// before
client.execute_command('CONFIG', 'GET', 'maxmemory')

// after
client.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')
Defensive patterns

Strategy: validation

Validate before calling

# For keyless/admin commands, always specify target_nodes
client.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')

Type guard

def is_keyless_command(cmd: str) -> bool:
    keyless = {'INFO', 'CONFIG', 'CLIENT', 'DBSIZE', 'FLUSHALL', 'FLUSHDB', 'PING', 'ECHO', 'SCRIPT', 'BGSAVE', 'SAVE', 'TIME', 'LASTSAVE'}
    return cmd.upper().split()[0] in keyless

Try / catch

from redis.exceptions import RedisClusterException
try:
    client.execute_command('CONFIG', 'GET', 'maxmemory')
except RedisClusterException as e:
    if 'specifying target nodes' in str(e):
        client.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')

Prevention

When it happens

Trigger: Calling a command with no keys (e.g., INFO, CONFIG GET, CLIENT LIST) via client.execute_command('INFO') without specifying target_nodes, or calling a command the key parser does not recognize. The guard is at cluster.py:1475-1484.

Common situations: Running admin/keyless commands on a cluster without a routing hint, or using a command not registered in the Redis COMMAND metadata so the key parser cannot extract keys.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/42f26e9272633b47. Report an issue: GitHub.

Appendix: source

Thrown at redis/cluster.py:1480

        if command.upper() in ("EVAL", "EVALSHA"):
            # command syntax: EVAL "script body" num_keys ...
            if len(args) <= 2:
                raise RedisClusterException(f"Invalid args in command: {args}")
            num_actual_keys = int(args[2])
            eval_keys = args[3 : 3 + num_actual_keys]
            # if there are 0 keys, that means the script can be run on any node
            # so we can just return a random slot
            if len(eval_keys) == 0:
                return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
            keys = eval_keys
        else:
            keys = self._get_command_keys(*args)
            if keys is None or len(keys) == 0:
                # FCALL can call a function with 0 keys, that means the function
                #  can be run on any node so we can just return a random slot
                if command.upper() in ("FCALL", "FCALL_RO"):
                    return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
                raise RedisClusterException(
                    "No way to dispatch this command to Redis Cluster. "
                    "Missing key.\nYou can execute the command by specifying "
                    f"target nodes.\nCommand: {args}"
                )

        # single key command
        if len(keys) == 1:
            return self.keyslot(keys[0])

        # multi-key command; we need to make sure all keys are mapped to
        # the same slot
        slots = {self.keyslot(key) for key in keys}
        if len(slots) != 1:
            raise RedisClusterException(
                f"{command} - all keys must map to the same key slot"
            )

        return slots.pop()

View on GitHub (pinned to 6a6b581b48)