Documentation
¶
Overview ¶
Package redislock provides distributed locking using Redis.
This implementation uses a naive "single instance" Redis distributed locking algorithm as described in https://redis.io/docs/latest/develop/use/patterns/distributed-locks/
We use the simple SET NX PX pattern which has edge cases where multiple nodes may acquire the lock under extreme circumstances (see the Redis documentation for details). We accept these edge cases because our primary use cases can tolerate occasional races:
- Infrastructure provisioning - infrequent, cloud providers handle concurrent attempts gracefully
- Migration coordination - prevents multiple nodes from running migrations simultaneously at startup; if a race occurs, the migration runner re-checks "already applied" status after acquiring the lock
- Initialization tasks - typically have "already exists" checks after acquiring lock
In the worst case, if an operation fails due to a lock race, the node will fail its health check and another node can take over. This is acceptable for startup-time operations that run infrequently.
Do NOT use this for high-frequency locking or cases where duplicate execution would cause data corruption. For those cases, consider Redlock or a proper distributed lock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.