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?
- A SETNX + EXPIRE (two operations, not atomic)
- B SET key value NX EX seconds (atomic, Redlock pattern) (correct answer)
- C INCR key and check value
- 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.