Which command atomically sets a key only if it does not exist, with a 30-second expiry, forming the basis of a distributed lock?
- A SET key value NX EX 30 (correct answer)
- B SETNX key value
- C SETEX key 30 value
- D MSETNX
Shortcut: SET with NX and EX in a single call is atomic. Separate SETNX and EXPIRE calls risk leaving a lock without a TTL if the client crashes between them.