redis/redis-py · error · RedisClusterException
No targets were found to execute {args} command on
Error message
No targets were found to execute {args} command on What it means
Raised in execute_command() when _determine_nodes() returns an empty list and no target_nodes were explicitly supplied. This means the request policy resolved to zero candidate nodes — typically because the cluster topology has no nodes of the required server type, or the routing policy produced nothing usable.
Source
Thrown at redis/asyncio/cluster.py:1185
if self._initialize:
await self.initialize(last_failed_node_name=last_failed_node_name)
last_failed_node_name = None
if (
len(target_nodes) == 1
and target_nodes[0] == self.get_default_node()
):
# Replace the default cluster node
self.replace_default_node()
try:
if not target_nodes_specified:
# Determine the nodes to execute the command on
target_nodes = await self._determine_nodes(
*args,
request_policy=command_policies.request_policy,
node_flag=passed_targets,
)
if not target_nodes:
raise RedisClusterException(
f"No targets were found to execute {args} command on"
)
if len(target_nodes) == 1:
# Return the processed result
ret = await self._execute_command(target_nodes[0], *args, **kwargs)
if command in self.result_callbacks:
ret = self.result_callbacks[command](
command, {target_nodes[0].name: ret}, **kwargs
)
return self._policies_callback_mapping[
command_policies.response_policy
](ret)
else:
keys = [node.name for node in target_nodes]
values = await asyncio.gather(
*(
asyncio.create_task(View on GitHub (pinned to da03cdc7e8)
Solutions
- Pass target_nodes explicitly to bypass policy resolution: target_nodes=RedisCluster.PRIMARIES.
- If read_from_replicas=True, ensure the cluster actually has replica nodes (check CLUSTER NODES); set read_from_replicas=False if not.
- Call await rc.refresh_nodes() / reconnect to refresh topology, then retry the command.
Example fix
// before
rc = RedisCluster.from_url(url, read_from_replicas=True)
await rc.get('k')
// after
rc = RedisCluster.from_url(url, read_from_replicas=False)
await rc.get('k') Defensive patterns
Strategy: fallback
Validate before calling
async def read_with_fallback(rc, key):
if rc.read_from_replicas:
replicas = rc.get_nodes_by_server_type('replica')
if not replicas:
# no replicas — route to a primary instead
return await rc.get(key, target_nodes=RedisCluster.PRIMARIES)
return await rc.get(key) Type guard
from redis.asyncio.cluster import RedisCluster
def has_routing_targets(rc: RedisCluster) -> bool:
return bool(rc.get_primaries()) or bool(rc.get_replicas()) Try / catch
from redis.cluster import RedisClusterException
try:
await rc.get('k')
except RedisClusterException as e:
if 'No targets' in str(e):
await rc.refresh_table_nodes() # or reload_exception()
await rc.get('k', target_nodes=RedisCluster.PRIMARIES)
else:
raise Prevention
- Before enabling read_from_replicas, confirm replicas exist via CLUSTER NODES.
- Build a retry wrapper that refreshes topology and falls back to PRIMARIES when no targets resolve.
- Monitor cluster topology health so degraded replica sets are caught early.
When it happens
Trigger: Issuing a replica-routed command (read_from_replicas=True) when the cluster has no replicas; a command whose policy targets ALL_NODES/REPLICAS but the slots cache or nodes cache is empty/degraded; a transient state during resharding where the relevant node group is momentarily empty.
Common situations: Enabling read_from_replicas against a single-node or no-replica cluster; querying immediately after a failover before topology refresh; a misconfigured cluster where replicas are not registered in CLUSTER SLOTS output.
Related errors
- No targets were found to execute {cmd.args} command on
- Cannot execute FT.CURSOR commands without FT.AGGREGATE
- No way to dispatch this command to Redis Cluster. Missing ke
- {cmd_name.upper()} command doesn't exist in Redis commands
- The requested node does not exist in the cluster.
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/d3ff38515127f427.json.
Report an issue: GitHub.