|Redis Developer Course||Redis Cloud Service||Redis-Gate Server|
Save multiple keys if Not eXists
Saves the given keys to their respective values.
MSETNX will not perform any operation at all even if just a single key already exists.
MSETNX is atomic, so all given keys are seved at once.
It is not possible for clients to see that some of the keys were updated while others are unchanged.
MSETNX key1 value1 key2 value2.
Integer reply, specifically:
- 1 if the all the keys were set.
- 0 if no key was set (at least one key already existed).
|command>||msetnx key1 Hello key2 Redis|
|command>||msetnx key2 XXXXX key3 Server|
|result>||0 Failed to save because key2 already exists |
|command>||mget key1 key2 key3|
|MSETNX is atomic, so all given keys are seved at once.|
MSETNX key value [key value ...]
- Available since 1.0.1.
- Time complexity(Logical processing time): O(N)
|Related Commands||SET, SETNX, MGET|
|Clients for Java||Jedis, Lettuce, Redisson||Clients for C||Hiredis|
To practice the command, click here to run Redis Web Client
|<< MGET||MSETNX||APPEND >>|
Click for a question or to see comments. Comments : Viewed :