All Questions
Redis medium

What is the recommended pattern for acquiring a resilient distributed lock in a single-instance Redis environment?

  1. A `SET lock_key unique_value NX PX 10000`: Ensures mutual exclusion with an automatic safety timeout.
  2. B `SET lock_key 1`: Simply sets a flag; relies on the application and users to check it manually.
  3. C `INCR lock_key`: Increments a counter; the lock is granted to the client that reaches exactly 10.
  4. D `LPUSH lock_key 1`: Adds a token to a list; the client that pops the token first owns the resource.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions