English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Redis Msetnx command is used to set one or more keys at the same time when all the given keys do not exist-value pair.
The basic syntax of the Redis Msetnx command is as follows:
redis 127.0.0.1:6379> MSETNX key1 value1 key2 value2 .. keyN valueN
>= 1.0.1
When all keys are successfully set, return 1 . If all given keys fail to set (at least one key already exists), then return 0 .
# MSETNX on non-existing keys redis> MSETNX rmdbs "MySQL" nosql "MongoDB" key-value-store "redis" (integer) 1 redis> MGET rmdbs nosql key-value-store 1) "MySQL" 2) "MongoDB" 3) "redis" # MSET has an existing key among the given keys redis> MSETNX rmdbs "Sqlite" language "python" # rmdbs key already exists, operation failed (integer) 0 redis> EXISTS language # language has not been set due to the atomicity of MSET (integer) 0 redis> GET rmdbs # rmdbs has not been modified "MySQL"