SET NX

The Redis SET option that writes a key only if it does not exist, as one atomic command. Exactly one of many concurrent callers wins, which makes it a claim or a lock; EX adds an expiry so a forgotten claim cannot live forever.

Minimal example

text
SET idem:42:abc pending NX EX 86400

Learn this concept

Lesson 3.9 · Idempotency keys

Used in exercises

Exercise 3.10 · POST /v1/orders: idempotent checkout Exercise 5.8 · Rider assignment worker Exercise 5.11 · Order location stream Exercise 8.2 · Stock reservation service Exercise 8.12 · Engineering walkthrough package
Prerequisite conceptsIdempotency key