redlock-py is a Python library that implements the Redis-based distributed lock manager algorithm (Redlock). It provides a mechanism for acquiring and releasing distributed locks across multiple independent Redis instances to ensure mutual exclusion in a distributed system. The library is currently at version 1.0.8, with a relatively low release cadence, as its PyPI project description was last updated in 2016 and the linked GitHub repository in 2021, suggesting a maintenance-level status.
pip install redlock-py redisVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to acquire and release a distributed lock using `redlock-py` with a context manager. It initializes the Redlock manager with Redis connection details and attempts to lock a resource. For a robust Redlock implementation, it's crucial to configure multiple independent Redis instances; the example uses a single instance for simplicity.
Understand the limitations of Redlock and assess if its 'correctness vs. efficiency' trade-offs are acceptable for your use case. For applications requiring strong correctness guarantees, consider alternative distributed consensus systems like ZooKeeper or etcd, or implement application-level fencing.
Ensure `redis` is installed in your environment: `pip install redlock-py redis`.
Deploy and configure `redlock-py` with a list of connection details for at least three independent Redis masters. Do not rely on master-replica replication for Redlock's fault tolerance.
If correctness is paramount, consider augmenting your system with an external mechanism for fencing tokens, or use a distributed lock system that inherently provides this feature.
Evaluate the project's suitability for long-term production use. Be prepared to maintain the library internally or consider more actively maintained alternatives if regular updates and support are critical.