{"record":{"id":"7f1e8b72f40bb827","repo":"redis/redis-py","slug":"invalid-args-in-command-args","errorCode":null,"errorMessage":"Invalid args in command: {args}","messagePattern":"Invalid args in command: (.+?)","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1465,"sourceCode":"            # The command contains the slot ID\n            return args[1]\n\n        # Get the keys in the command\n\n        # CLIENT TRACKING is a special case.\n        # It doesn't have any keys, it needs to be sent to the provided nodes\n        # By default it will be sent to all nodes.\n        if command.upper() == \"CLIENT TRACKING\":\n            return None\n\n        # EVAL and EVALSHA are common enough that it's wasteful to go to the\n        # redis server to parse the keys. Besides, there is a bug in redis<7.0\n        # where `self._get_command_keys()` fails anyway. So, we special case\n        # EVAL/EVALSHA.\n        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}\"","sourceCodeStart":1447,"sourceCodeEnd":1483,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L1447-L1483","documentation":"Raised as a RedisClusterException by determine_slot() when EVAL or EVALSHA is called with too few arguments (len(args) <= 2), meaning the command is missing the required numkeys parameter. The cluster client special-cases EVAL/EVALSHA to extract keys locally (due to a Redis <7.0 server bug), so it needs at least the command name, script body, and numkeys to proceed.","triggerScenarios":"Calling client.eval(script) or client.eval(script, ) with fewer than 3 positional args, or client.execute_command('EVAL', script) without the numkeys argument. The guard at cluster.py:1464-1465 fires.","commonSituations":"Calling eval() with the wrong arity, forgetting the numkeys argument, or passing a pre-built arg list that was truncated.","solutions":["Provide the full EVAL signature: client.eval(script, numkeys, *keys_and_args) with at least numkeys specified.","For EVALSHA, ensure all three required parts are present: client.evalsha(sha1, numkeys, *keys_and_args)."],"exampleFix":"// before\nclient.eval('return 1')\n\n// after\nclient.eval('return 1', 0)","handlingStrategy":"validation","validationCode":"# Validate EVAL/EVALSHA arity before calling\ndef safe_eval(client, script, numkeys, *keys_and_args):\n    if numkeys is None:\n        raise ValueError('numkeys is required for EVAL in cluster mode')\n    return client.eval(script, numkeys, *keys_and_args)","typeGuard":"def eval_args_valid(args: list) -> bool:\n    # EVAL/EVALSHA need at least: command, script/sha, numkeys\n    return len(args) > 2","tryCatchPattern":"null","preventionTips":["Always provide the numkeys argument when calling eval() or evalsha().","For zero-key scripts, explicitly pass numkeys=0: client.eval(script, 0).","Validate your argument list length before calling execute_command with EVAL/EVALSHA."],"tags":["eval","lua-scripting","cluster","arguments"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}