Redis › Transactions
How do Redis transactions interact with Redis Cluster when the queued commands involve keys located on different shards?
AdvancedAnswer
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'
EXECReal-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.