Use Redlock for distributed locking
masterRedlock provides a safe and reliable lock to coordinate access to resources shared across threads, processes, and machines using Redis. It implements the Python threading.Lock API.
Best Practices:
- Instantiate per use: It is safest to instantiate a new
Redlockobject every time you need to protect a resource rather than sharing instances. Use thekeyto identify the resource. - Avoid single points of failure: In production, use 5 Redis masters so the lock remains available even if 2 masters are lost.
- Manage timeouts: Locks are automatically released to prevent deadlocks. Ensure your critical section completes well within the
auto_release_time(default is 10 seconds).