Stock Hold

A stock hold is a temporary Redis reservation that marks units as taken while an order is being processed or paid for. In this course, holds use SET NX EX 300 to create a five-minute reservation, while MySQL remains responsible for preventing overselling.

Minimal example

text
SET resv:order-123:item-42 1 NX EX 300

The key expires automatically after 300 seconds.

Learn this concept

Lesson 8.1 · Optimistic locking for stock

Used in exercises

Exercise 8.2 · Stock reservation service
Prerequisite conceptsSET NXRedis TTLIdempotency key