SETNX
Stores a string only when its key does not exist.
Strings · Example verified
Syntax covered here
SETNX key valueThe cases exercise rejection for an existing key and successful creation of a missing key, followed by GET.
Tested example & replies
Requests below run in order against an empty database. Each connection authenticates with the fixture password first. Quoted values are strings; null is a nil reply; arrays preserve RESP order.
# connection: default
> SET greeting hello
"OK"
# connection: default
> SETNX greeting world
0
# connection: default
> SETNX fresh world
1
# connection: default
> GET fresh
"world"