Locking multiple resources in a Redis Cluster
mainWhen using a Redis Cluster, all keys in a single command must belong to the same node. If you need to lock multiple resources together using redlock, you MUST use Redis hash tags (e.g., {tag}key) to ensure all resource strings resolve to the same node.
Strategies:
- Generic Prefix: Use a single generic prefix like
{redlock}my_resourceto ensure all lock keys resolve to the same node. - Attribute-based Tagging: Use a common attribute (like a tenant ID) as a hash tag, e.g.,
{tenant123}resource_name, to balance distribution while allowing multi-resource locks for that specific tenant.