Q39 Redis Domain 2 · 25–30% of exam

A team needs to implement a distributed lock in Redis to prevent concurrent access to a shared resource across multiple application instances. Which approach is recommended?

  1. A SETNX + EXPIRE (two operations, not atomic)
  2. B SET key value NX EX seconds (atomic, Redlock pattern) (correct answer)
  3. C INCR key and check value
  4. D LPUSH/BRPOPLPUSH

Shortcut: SET key value NX EX seconds atomically sets the key only if it doesn't exist (NX) with an expiry. This is the foundation of the Redlock algorithm for distributed locking.