redis/redis-py · error · RedisClusterException
At least a command with a key is needed to identify a node
Error message
At least a command with a key is needed to identify a node
What it means
Thrown by ClusterPipeline._get_client_and_connection_for_transaction when self._pipeline_slots is empty. A cluster transaction must be routed to a single node, which is chosen from the slot of the first queued key; with no key-bearing command in the pipeline the library cannot decide which node owns the transaction. This is a programming-error guard, not a transient runtime fault.
Source
Thrown at redis/asyncio/cluster.py:3097
self._executing = False
self._retry = copy(self._pipe.cluster_client.retry)
self._retry.update_supported_errors(
RedisCluster.ERRORS_ALLOW_RETRY + self.SLOT_REDIRECT_ERRORS
)
def _get_client_and_connection_for_transaction(
self,
) -> Tuple[ClusterNode, Connection]:
"""
Find a connection for a pipeline transaction.
For running an atomic transaction, watch keys ensure that contents have not been
altered as long as the watch commands for those keys were sent over the same
connection. So once we start watching a key, we fetch a connection to the
node that owns that slot and reuse it.
"""
if not self._pipeline_slots:
raise RedisClusterException(
"At least a command with a key is needed to identify a node"
)
node: ClusterNode = self._pipe.cluster_client.nodes_manager.get_node_from_slot(
list(self._pipeline_slots)[0], False
)
self._transaction_node = node
if not self._transaction_connection:
connection: Connection = self._transaction_node.acquire_connection()
self._transaction_connection = connection
return self._transaction_node, self._transaction_connection
def execute_command(self, *args: Union[KeyT, EncodableT], **kwargs: Any) -> "Any":
# Given the limitation of ClusterPipeline sync API, we have to run it in thread.
response = None
error = NoneView on GitHub (pinned to da03cdc7e8)
Solutions
- Queue at least one command whose first arg is a key (e.g. pipeline.set('k','v')) so the pipeline can resolve a slot before execute().
- If you only need keyless/admin commands, use the regular cluster client (await client.config_get()) instead of a transactional pipeline.
- If you must run keyless commands atomically, route them explicitly to one node via client.get_node_from_key or a standalone connection rather than the cluster pipeline.
Example fix
// before pipe = client.pipeline(transaction=True) await pipe.config_get() await pipe.execute() # raises [80] // after await client.config_get() # no transaction needed
Defensive patterns
Strategy: validation
Validate before calling
# Before execute(), ensure at least one key-bearing command is queued
has_key_cmd = any(
cmd.args and cmd.args[0] not in NO_SLOTS_COMMANDS
for cmd in pipe._command_queue
)
if not has_key_cmd:
raise ValueError('Cluster transaction needs at least one key command') Try / catch
from redis.exceptions import RedisClusterException
try:
await pipe.execute()
except RedisClusterException as e:
if 'At least a command with a key' in str(e):
# add a key-bearing command or skip the transaction
... Prevention
- Always queue at least one key command in a transactional cluster pipeline.
- Use the regular client for admin/keyless commands instead of a transaction.
When it happens
Trigger: Calling .execute() (or any execution path that reaches _get_client_and_connection_for_transaction) on an asyncio Redis Cluster pipeline that has only queued keyless commands (e.g. pipeline.config_get(), pipeline.info()) or has an empty command queue while _watching/_pipeline_slots are unset.
Common situations: Building a cluster pipeline out of only administrative commands (INFO, CONFIG, CLIENT, FLUSHDB), or forgetting to queue the actual key command before execute() in a transactional block, or calling WATCH with no subsequent key command.
Related errors
- At least a command with a key is needed to identify a node
- Cannot watch or send commands on different slots
- Cannot identify slot number for command: {args[0]},it cannot
- Cannot issue a WATCH after a MULTI
- All keys involved in a cluster transaction must map to the s
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/59c7013634669214.json.
Report an issue: GitHub.