Back to results for “Commands”
Redis › Transactions

How do Redis transactions interact with Redis Cluster when the queued commands involve keys located on different shards?

Advanced

Answer

In Redis Cluster, all keys accessed within a single transaction must map to the same hash slot, meaning they typically need to reside on the same shard, so applications commonly use hash tags in key names to force related keys into the same slot, ensuring the transaction can execute successfully across a sharded cluster.
MULTI
SET '{user:1000}:profile' 'data'
SET '{user:1000}:settings' 'data'
EXEC
Real-world example A multi tenant application uses hash tags in its key naming scheme so that all keys belonging to the same customer land on the same cluster shard, allowing transactions involving multiple related keys for that customer to execute successfully.

Common follow-ups: What error does Redis return if a transaction spans multiple hash slots?;How do hash tags affect the overall distribution of keys across the cluster?