redlock is a Python implementation of the Redlock algorithm for distributed locks with Redis. It provides a simple API to acquire and release locks across multiple Redis instances to ensure reliability in distributed systems. The current version is 1.2.0, with a release cadence that is not very frequent, suggesting a stable but less actively developed library.
pip install redlockVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Redlock with a single Redis instance (for demonstration) and acquire/release a distributed lock. In a real-world scenario, you should configure multiple independent Redis master instances to leverage the Redlock algorithm's fault tolerance. The `lock_ttl` is specified in milliseconds.
Always provide the `ttl` value in milliseconds. E.g., for a 5-second lock, use `5000`.
Provide `Redlock` with a list of at least 3 Redis master instances in `redis_masters`. Ensure these instances are physically distinct and independent.
Estimate the maximum time your critical section will take and set `lock_ttl` accordingly, with a safety margin. If operations can exceed this, consider breaking them down or finding alternative coordination mechanisms.