redis/redis-py · error · RedisClusterException
No targets were found to execute
Error message
No targets were found to execute {cmd.args} command on What it means
Pipeline-side counterpart of error 65, raised in ClusterPipeline._execute() when _determine_nodes() returns an empty list for a queued command. The pipeline groups commands by target node before sending, so a command that resolves to zero nodes cannot be placed anywhere and aborts the whole pipeline execution.
Solutions
- Await rc.initialize() before building the pipeline so the slots/node cache is populated.
- Set explicit target_nodes= on the queued command to bypass key/policy resolution.
- Confirm the target node group is non-empty (rc.get_primaries() / get_replicas()) before pipelining against it.
- Retry the pipeline after a topology refresh if the cache was transiently empty.
Example fix
// before
pipe = rc.pipeline()
pipe.execute_command('GET', 'x', target_nodes=rc.REPLICAS) # no replicas
await pipe.execute()
// after
await rc.initialize()
pipe = rc.pipeline()
pipe.get('x')
await pipe.execute() Defensive patterns
Strategy: validation
Validate before calling
async def safe_pipeline(rc):
await rc.initialize()
if not rc.get_primaries():
raise RuntimeError('cluster has no primaries; cannot pipeline')
return rc.pipeline() Type guard
null
Try / catch
from redis.exceptions import RedisClusterException
for _ in range(3):
try:
pipe = rc.pipeline()
# ...queue commands...
return await pipe.execute()
except RedisClusterException as e:
if 'No targets were found' not in str(e):
raise
await rc.initialize() Prevention
- Await rc.initialize() before constructing a pipeline.
- Set explicit target_nodes on queued commands that may resolve to empty node groups.
- Confirm primaries/replicas exist before pipelining against those groups.
When it happens
Trigger: Queuing a command on a cluster pipeline whose policy resolves to an empty node set, e.g. a replica-routed command when no replicas are cached, or any command before the cluster cache is populated (initialize() not yet run / failed).
Common situations: Building a pipeline immediately after constructing RedisCluster without awaiting initialize(); cluster mid-failover with an empty primaries/replicas cache; read_from_replicas with no replicas deployed.
Related errors
- No targets were found to execute
- At least a command with a key is needed to identify a node
- Cannot identify slot number for command
- No targets were found to execute
- Slot " " is not covered by the cluster.
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/860ade2484c2cfc4.
Report an issue: GitHub.
Appendix: source
Thrown at redis/asyncio/cluster.py:2940
response_policy=ResponsePolicy.DEFAULT_KEYED,
)
else:
if command_flag in client._command_flags_mapping:
command_policies = CommandPolicies(
request_policy=client._command_flags_mapping[
command_flag
]
)
else:
command_policies = CommandPolicies()
target_nodes = await client._determine_nodes(
*cmd.args,
request_policy=command_policies.request_policy,
node_flag=passed_targets,
)
if not target_nodes:
raise RedisClusterException(
f"No targets were found to execute {cmd.args} command on"
)
cmd.command_policies = command_policies
if len(target_nodes) > 1:
raise RedisClusterException(f"Too many targets for command {cmd.args}")
node = target_nodes[0]
if node.name not in nodes:
nodes[node.name] = (node, [])
nodes[node.name][1].append(cmd)
# Start timing for observability
start_time = time.monotonic()
errors = await asyncio.gather(
*(
asyncio.create_task(node[0].execute_pipeline(node[1]))
for node in nodes.values()
)View on GitHub (pinned to 6a6b581b48)