MSETNX
MSETNX key value [key value ...]
- Group
- String
- Complexity
- O(N) for N keys
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- write
- Keys
- first 1, last final argument, step 2
- HotKV Cloud
- All plans
- On-Premise
- no license needed
MSETNX stores all the given key-value pairs only when none of the keys
exist. If even one key exists, nothing is written. The check and the writes
happen as one step, which makes MSETNX useful for claiming a group of names
together.
In a cluster, all keys must hash to the same slot.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| All keys were set | Integer 1 |
Integer 1 |
| At least one key existed, nothing was set | Integer 0 |
Integer 0 |
Examples
Section titled “Examples”127.0.0.1:6379> MSETNX seat:1 "ada" seat:2 "grace"(integer) 1127.0.0.1:6379> MSETNX seat:2 "linus" seat:3 "ken"(integer) 0127.0.0.1:6379> EXISTS seat:3(integer) 0Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.