Distributed Locking (Redlock)

Difficulty: Advanced

Question

How do you implement a distributed lock in Redis?

Answer

Use `SET resource_name my_random_value NX PX 30000`. The 'NX' ensures only one setter wins, and 'PX' prevents deadlocks if the client crashes.

Concepts covered

SETNX, Redlock, Race Conditions, Resource Locking