redis/redis-py · error · RedisError

{cmd_name} command doesn't exist in Redis commands

Error message

{cmd_name} command doesn't exist in Redis commands

What it means

Raised by the sync CommandsParser.get_keys() (redis/_parsers/commands.py:150) when a command name is not found in the cached COMMAND output even after a fresh re-initialization (self.initialize()). The cluster client calls get_keys() to learn which slots to route keys to; if the server does not know the command, key positions cannot be determined. It is raised as RedisError("<CMD> command doesn't exist in Redis commands").

Source

Thrown at redis/_parsers/commands.py:150

        if len(args) < 2:
            # The command has no keys in it
            return None

        cmd_name = args[0].lower()
        if cmd_name not in self.commands:
            # try to split the command name and to take only the main command,
            # e.g. 'memory' for 'memory usage'
            cmd_name_split = cmd_name.split()
            cmd_name = cmd_name_split[0]
            if cmd_name in self.commands:
                # save the split command to args
                args = cmd_name_split + list(args[1:])
            else:
                # We'll try to reinitialize the commands cache, if the engine
                # version has changed, the commands may not be current
                self.initialize(redis_conn)
                if cmd_name not in self.commands:
                    raise RedisError(
                        f"{cmd_name.upper()} command doesn't exist in Redis commands"
                    )

        command = self.commands.get(cmd_name)
        if "movablekeys" in command["flags"]:
            keys = self._get_moveable_keys(redis_conn, *args)
        elif "pubsub" in command["flags"] or command["name"] == "pubsub":
            keys = self._get_pubsub_keys(*args)
        else:
            if (
                command["step_count"] == 0
                and command["first_key_pos"] == 0
                and command["last_key_pos"] == 0
            ):
                is_subcmd = False
                if "subcommands" in command:
                    subcmd_name = f"{cmd_name}|{args[1].lower()}"
                    for subcmd in command["subcommands"]:

View on GitHub (pinned to 6a6b581b48)

Solutions

  1. Verify the exact command name/casing against the server with redis-cli COMMAND INFO <name>.
  2. Ensure any module providing the command is loaded (MODULE LIST) on every cluster node.
  3. For custom/module commands, use the dedicated module API rather than routing through cluster get_keys.
  4. Align Redis versions across cluster nodes so COMMAND output is consistent.

Example fix

# before
await r.execute_command("ST", "key", "val")  # typo -> 'ST command doesn't exist'

# after
await r.execute_command("SET", "key", "val")
Defensive patterns

Strategy: validation

Validate before calling

# Validate a command exists in the server's COMMAND cache before routing
known = r.execute_command("COMMAND")  # dict of command names
name = "MYCMD"
if name.lower() not in {k.lower() for k in known}:
    raise ValueError(f"{name} is not a registered Redis command")

Try / catch

try:
    r.execute_command("MYCMD", "key")
except redis.RedisError as e:
    if "command doesn't exist in Redis commands" in str(e):
        # typo / module not loaded / rename-command
        ...

Prevention

When it happens

Trigger: Running a command in Redis Cluster whose name isn't registered with the server: a typo, a custom/module command whose module isn't loaded, or a command renamed via rename-command. get_keys() splits the name (e.g. 'memory usage' -> 'memory'), re-queries COMMAND, and still fails.

Common situations: Typos like r.execute_command('ST'); calling a module command (e.g. JSON.GET) without the module loaded; rename-command in redis.conf; cluster nodes running different Redis versions so COMMAND output differs; very old server missing a newer command.

Related errors


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