We often use Redis to coordinate work across multiple application instances.
A common solution is a distributed lock.
At first glance, implementing one looks simple:
SET lock:report:123 unique-token NX EX 30
Enter fullscreen mode
Exit fullscreen mode
If the key doesn't exist, Redis creates it. If another process already holds the lock, the acquisition fails.
But here's a question that makes distributed locking more interesting:
What happens when the lock expires while the process holding it is still running?
Does Redis stop the process?
Does the process automatically know that it lost ownership?
Can another server start performing the same operation?
Let's explore.
1.…