{"id":"3f77a7571718fcca","repo":"redis/redis-py","slug":"command-all-keys-must-map-to-the-same-key-slot-3f77a7","errorCode":null,"errorMessage":"{command} - all keys must map to the same key slot","messagePattern":"(.+?) - all keys must map to the same key slot","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1494,"sourceCode":"                # 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()\n\n    def get_encoder(self):\n        \"\"\"\n        Get the connections' encoder\n        \"\"\"\n        return self.encoder\n\n    def get_connection_kwargs(self):\n        \"\"\"\n        Get the connections' key-word arguments\n        \"\"\"\n        return self.nodes_manager.connection_kwargs\n\n    def _is_nodes_flag(self, target_nodes):","sourceCodeStart":1476,"sourceCodeEnd":1512,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L1476-L1512","documentation":"Error \"{command} - all keys must map to the same key slot\" thrown in redis/redis-py.","triggerScenarios":"Thrown at redis/cluster.py:1494 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}