redis/redis-py · error · ValueError
Command {command_name} not found in commands
Error message
Command {command_name} not found in commands What it means
Raised by CommandsParser._is_keyless_command() when no subcommand is supplied but command_name is not a key in self.commands. This means the policy/keyless lookup is being run for a command the parser never received from COMMAND. Distinct from error 4 in that this fires during the keyless-policy computation loop rather than the routing get_keys() path.
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 da03cdc7e8)
Solutions
- Avoid concurrent calls that reinitialize() the parser while another caller is computing policies; serialize topology refresh.
- Validate command_name in self.commands before invoking _is_keyless_command.
- Upgrade redis-py - later versions guard against the concurrent-clear race.
- Recreate the CommandsParser if the underlying connection was reset.
Example fix
// before
parser._is_keyless_command("mycmd") # ValueError if 'mycmd' missing
// after
if "mycmd" not in parser.commands:
parser.initialize(redis_conn)
assert "mycmd" in parser.commands
parser._is_keyless_command("mycmd") Defensive patterns
Strategy: validation
Validate before calling
# Validate the command is in the cache before the keyless lookup
def assert_command_known(parser, name):
if name not in parser.commands:
parser.initialize(parser.redis_connection)
if name not in parser.commands:
raise KeyError(f"command '{name}' not in COMMAND output") Try / catch
try:
parser._is_keyless_command(name)
except ValueError as e:
if "not found in commands" in str(e):
parser.initialize(parser.redis_connection) # refresh then retry once
parser._is_keyless_command(name) Prevention
- Serialize topology/policy refresh so initialize() does not race with iteration.
- Validate command names against parser.commands before policy lookups.
- Recreate the CommandsParser after a cluster reset instead of reusing a stale one.
- Upgrade redis-py to pick up race-condition guards.
When it happens
Trigger: get_command_policies() iterating over self.commands and calling _is_keyless_command(command) for a name that was somehow removed from the dict concurrently; calling _is_keyless_command directly with a command name that COMMAND did not return; race where the cache was cleared mid-iteration.
Common situations: Concurrent reinitialize() clearing self.commands while another thread iterates; passing a stale command name captured before a reconnect; misbehaving module that mutates the parser's commands dict.
Related errors
- Subcommand {subcommand_name} not found in command {command_n
- {cmd_name.upper()} command doesn't exist in Redis commands
- Incorrect request policy type: {policy_type}
- Incorrect response policy type: {policy_type}
- Cannot identify slot number for command: {args[0]},it cannot
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/12663951e959bb20.json.
Report an issue: GitHub.