redis/redis-py · error · ValueError

Command not found in commands

Error message

Command {command_name} not found in commands

What it means

Raised by the sync CommandsParser._is_keyless_command() (redis/_parsers/commands.py:253) when command_name is absent from self.commands (the populated COMMAND cache). It is raised as ValueError and indicates the commands dict was queried for a command that was never cached or was removed.

Solutions

  1. Ensure CommandsParser.initialize() fully completes before get_command_policies() is called.
  2. Avoid concurrent reinit that could clear self.commands while policies are being computed.
  3. Re-run initialize() against a healthy node and retry get_command_policies().
  4. If it reproduces with a fully initialized cache, report it as a bug with the COMMAND output attached.
Defensive patterns

Strategy: validation

Validate before calling

# Ensure the COMMAND cache is initialized before computing policies
from redis._parsers.commands import CommandsParser
p = CommandsParser(r)
assert p.commands, "commands cache is empty; initialize() did not complete"
# then call p.get_command_policies()

Prevention

When it happens

Trigger: get_command_policies() calls _is_keyless_command(command) for each entry it is iterating, so under normal flow the key exists. This fires when self.commands was concurrently cleared/replaced, when a caller invokes _is_keyless_command with an arbitrary name, or when initialization is incomplete.

Common situations: Concurrent reinitialization resetting self.commands mid-policy-build; a code path passing a name not obtained from COMMAND; partial initialization due to a connection error during COMMAND.

Related errors


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

Appendix: source

Thrown at redis/_parsers/commands.py:253

        Raises:
            ValueError
                If the specified subcommand is not found within the command or the
                specified command does not exist in the available commands.
        """
        if subcommand_name:
            for subcommand in self.commands.get(command_name)["subcommands"]:
                if str_if_bytes(subcommand[0]) == subcommand_name:
                    parsed_subcmd = self.parse_subcommand(subcommand)
                    return parsed_subcmd["first_key_pos"] <= 0
            raise ValueError(
                f"Subcommand {subcommand_name} not found in command {command_name}"
            )
        else:
            command_details = self.commands.get(command_name, None)
            if command_details is not None:
                return command_details["first_key_pos"] <= 0

            raise ValueError(f"Command {command_name} not found in commands")

    def get_command_policies(self) -> PolicyRecords:
        """
        Retrieve and process the command policies for all commands and subcommands.

        This method traverses through commands and subcommands, extracting policy details
        from associated data structures and constructing a dictionary of commands with their
        associated policies. It supports nested data structures and handles both main commands
        and their subcommands.

        Returns:
            PolicyRecords: A collection of commands and subcommands associated with their
            respective policies.

        Raises:
            IncorrectPolicyType: If an invalid policy type is encountered during policy extraction.
        """
        command_with_policies = {}

View on GitHub (pinned to 6a6b581b48)