redis/redis-py · error · RedisClusterException
No targets were found to execute {c.args} command on
Error message
No targets were found to execute {c.args} command on What it means
Raised in PipelineStrategy._send_cluster_commands (redis/cluster.py:4291) when _determine_nodes() returns an empty list for a queued command. The cluster pipeline requires each command to resolve to at least one node; if the command has no key, no predefined routing flag, and no explicit target_nodes, there is no node to send it to. This is a routing-resolution failure, not a network error.
Source
Thrown at redis/cluster.py:4291
response_policy=ResponsePolicy.DEFAULT_KEYED,
)
else:
if command_flag in self._pipe._command_flags_mapping:
command_policies = CommandPolicies(
request_policy=self._pipe._command_flags_mapping[
command_flag
]
)
else:
command_policies = CommandPolicies()
target_nodes = self._determine_nodes(
*c.args,
request_policy=command_policies.request_policy,
node_flag=passed_targets,
)
if not target_nodes:
raise RedisClusterException(
f"No targets were found to execute {c.args} command on"
)
c.command_policies = command_policies
if len(target_nodes) > 1:
raise RedisClusterException(
f"Too many targets for command {c.args}"
)
node = target_nodes[0]
if node == self._pipe.get_default_node():
is_default_node = True
# now that we know the name of the node
# ( it's just a string in the form of host:port )
# we can build a list of commands for each node.
node_name = node.name
if node_name not in nodes:
redis_node = self._pipe.get_redis_connection(node)View on GitHub (pinned to da03cdc7e8)
Solutions
- Pass an explicit target to the keyless command: pipe.info(target_nodes=RedisCluster.PRIMARIES) or pipe.info(target_nodes=RedisCluster.DEFAULT_NODE).
- Use the non-pipeline client API for admin commands: rc.info(target_nodes=RedisCluster.PRIMARIES).
- If you requested REPLICAS/ALL_NODES, verify the cluster actually has those nodes via rc.cluster_nodes() and fall back to PRIMARIES when empty.
- For custom/module commands, ensure COMMAND INFO is reachable so the resolver can derive routing, or always pass target_nodes explicitly.
Example fix
# before pipe = rc.pipeline() pipe.info() # no key -> no resolvable target pipe.execute() # after pipe = rc.pipeline() pipe.info(target_nodes=RedisCluster.PRIMARIES) pipe.execute()
Defensive patterns
Strategy: validation
Validate before calling
from redis.cluster import RedisCluster
def queue_keyless_in_pipeline(pipe, cmd, *args, target=None):
# keyless commands need an explicit target in a cluster pipeline
if target is None:
target = RedisCluster.PRIMARIES
getattr(pipe, cmd)(*args, target_nodes=target)
return pipe Try / catch
from redis.exceptions import RedisClusterException
try:
pipe.info()
pipe.execute()
except RedisClusterException as e:
if 'No targets were found' in str(e):
rc.info(target_nodes=RedisCluster.PRIMARIES) # run on client with target
else:
raise Prevention
- Always pass target_nodes for keyless/admin commands in a cluster pipeline.
- Verify the requested node group is non-empty with rc.cluster_nodes() before relying on REPLICAS/ALL_NODES.
- Prefer the non-pipeline client API for admin commands like INFO/CONFIG/CLIENT.
When it happens
Trigger: Queuing a keyless command with no target_nodes in a cluster pipeline (e.g. pipe.info(), pipe.config_get(), pipe.client_getname()) when no default node exists, or passing target_nodes=REPLICAS when the cluster currently has zero replicas. Also when an unknown/custom command has no COMMAND INFO metadata and no key.
Common situations: Calling administrative or keyless commands (INFO, CONFIG, CLIENT, DEBUG) through a cluster pipeline without specifying target_nodes. Cluster deployed with primaries only (no replicas) while code requests target_nodes=RedisCluster.REPLICAS. Using a custom command module whose COMMAND INFO is not loaded. Default node unavailable after a topology change.
Related errors
- At least a command with a key is needed to identify a node
- Too many targets for command {c.args}
- At least a command with a key is needed to identify a node
- Cannot identify slot number for command: {args[0]},it cannot
- {cmd_name.upper()} command doesn't exist in Redis commands
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/985a39461c0cf9ec.json.
Report an issue: GitHub.