Hunter Zhao
Hunter Zhao

Reputation: 4669

Is Redis' set command an atomic operation?

I'm trying to use Redis' set command to implement a simplest distributed lock component, but I can't find any exact basis about atomicity through the official document, is Redis' SET key value [EX seconds] [PX milliseconds] [NX|XX] command an atomic operation?

Upvotes: 22

Views: 16039

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064184

Yes. The core is single threaded, so nothing will run until the SET has completed; that makes SET {key} {value} EX {expiry} NX ideal for simple locking.

Upvotes: 43

Related Questions