{"record":{"id":"42f26e9272633b47","repo":"redis/redis-py","slug":"no-way-to-dispatch-this-command-to-redis-cluster-42f26e","errorCode":null,"errorMessage":"No way to dispatch this command to Redis Cluster. Missing key.\nYou can execute the command by specifying target nodes.\nCommand: {args}","messagePattern":"No way to dispatch this command to Redis Cluster\\. Missing key\\.\nYou can execute the command by specifying target nodes\\.\nCommand: (.+?)","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1480,"sourceCode":"        if command.upper() in (\"EVAL\", \"EVALSHA\"):\n            # command syntax: EVAL \"script body\" num_keys ...\n            if len(args) <= 2:\n                raise RedisClusterException(f\"Invalid args in command: {args}\")\n            num_actual_keys = int(args[2])\n            eval_keys = args[3 : 3 + num_actual_keys]\n            # if there are 0 keys, that means the script can be run on any node\n            # so we can just return a random slot\n            if len(eval_keys) == 0:\n                return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)\n            keys = eval_keys\n        else:\n            keys = self._get_command_keys(*args)\n            if keys is None or len(keys) == 0:\n                # FCALL can call a function with 0 keys, that means the function\n                #  can be run on any node so we can just return a random slot\n                if command.upper() in (\"FCALL\", \"FCALL_RO\"):\n                    return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)\n                raise RedisClusterException(\n                    \"No way to dispatch this command to Redis Cluster. \"\n                    \"Missing key.\\nYou can execute the command by specifying \"\n                    f\"target nodes.\\nCommand: {args}\"\n                )\n\n        # single key command\n        if len(keys) == 1:\n            return self.keyslot(keys[0])\n\n        # multi-key command; we need to make sure all keys are mapped to\n        # the same slot\n        slots = {self.keyslot(key) for key in keys}\n        if len(slots) != 1:\n            raise RedisClusterException(\n                f\"{command} - all keys must map to the same key slot\"\n            )\n\n        return slots.pop()","sourceCodeStart":1462,"sourceCodeEnd":1498,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L1462-L1498","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an explicit target_nodes argument, e.g. client.execute_command('INFO', target_nodes='PRIMARIES') or target_nodes='ALL_NODES'.","For commands that affect all nodes, use the nodes_flag constants PRIMARIES, REPLICAS, ALL_NODES, or RANDOM.","If the command should have keys, verify the command name is recognized by Redis COMMAND INFO so the key parser can extract them."],"exampleFix":"// before\nclient.execute_command('CONFIG', 'GET', 'maxmemory')\n\n// after\nclient.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')","handlingStrategy":"validation","validationCode":"# For keyless/admin commands, always specify target_nodes\nclient.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')","typeGuard":"def is_keyless_command(cmd: str) -> bool:\n    keyless = {'INFO', 'CONFIG', 'CLIENT', 'DBSIZE', 'FLUSHALL', 'FLUSHDB', 'PING', 'ECHO', 'SCRIPT', 'BGSAVE', 'SAVE', 'TIME', 'LASTSAVE'}\n    return cmd.upper().split()[0] in keyless","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    client.execute_command('CONFIG', 'GET', 'maxmemory')\nexcept RedisClusterException as e:\n    if 'specifying target nodes' in str(e):\n        client.execute_command('CONFIG', 'GET', 'maxmemory', target_nodes='PRIMARIES')","preventionTips":["Always pass target_nodes for keyless/admin commands in cluster mode.","Learn the node_flag constants: PRIMARIES, REPLICAS, ALL_NODES, RANDOM.","Check whether your command has keys; if not, it needs explicit routing."],"tags":["cluster-routing","keyless-command","target-nodes"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}