Exclusive claim with SET NX PX

An exclusive Redis claim is a temporary lease created with SET key value NX PX milliseconds. NX ensures that only one concurrent operation can create the claim, while PX automatically expires it after the specified duration. The stored value identifies the owner and must be checked before the claim is released.

Minimal example

go
acquired, err := rdb.SetNX(
    ctx,
    "order:501:claim",
    "offer-8f3a",
    30*time.Second,
).Result()
if err != nil {
    return err
}

Learn this concept

Lesson 5.6 · Redis GEO and SET NX PX

Used in exercises

Exercise 5.8 · Rider assignment worker Exercise 5.11 · Order location stream Exercise 5.13 · Hub broadcast and claim race tests
Prerequisite conceptsRedis TTLSET NX