SETNX

Since 1.1.0Strings

Syntax

SETNX key value
  • Flags: fast, write
  • ACL categories: @fast, @string, @write
  • Arity: 3

Sets key to value only if the key does not exist. It is SET key value NX with an integer reply.

Reply

  • 1 if the key was set.
  • 0 if the key already existed, and nothing changed.

Examples

> SETNX lock owner-1
(integer) 1
> SETNX lock owner-2
(integer) 0