Menu

1 / 4

Redis Distributed Locks: The Lock Expired, But the Process Is Still Running

DEV Community: redis·Abhinav·2 days ago
#UUfqRQOG
#devtoredis#devto#dev#lock#server
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.