SET
Stores a string, optionally with tested existence conditions or expiry.
Strings · Example verified
Syntax covered here
SET key value | SET key value EX seconds | SET key value NX [EX seconds] | SET key value XX GETNX skips an existing key and creates a missing one; NX with EX is also accepted. XX GET replaces an existing value while returning its previous value.
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
> SET greeting world NX
null
# connection: default
> SET fresh world NX EX 60
"OK"
# connection: default
> GET fresh
"world"
# connection: default
> SET fresh changed XX GET
"world"
# connection: default
> GET fresh
"changed"