My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

We moved to Redis.io!

Redis home moved to http://redis.io, please visit our new home.

MsetCommand  
Updated Dec 8, 2009 by simonwil...@gmail.com

MSET key1 value1 key2 value2 ... keyN valueN (Redis >= 1.1)

MSETNX key1 value1 key2 value2 ... keyN valueN (Redis >= 1.1)

Time complexity: O(1) to set every key

Set the the respective keys to the respective values. MSET will replace old values with new values, while MSETNX will not perform any operation at all even if just a single key already exists.
Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.
Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another client talking to Redis can either see the changes to both A and B at once, or no modification at all.

MSET Return value

Status code reply Basically +OK as MSET can't fail

MSETNX Return value

Integer reply, specifically:

1 if the all the keys were set
0 if no key was set (at least one key already existed)
Comment by tczol...@gmail.com, Dec 18, 2009

is there an opportunity to somehow "escape" or quote spaces in key names and values?

i would like to insert values with arbitrary keys (including spaces either), just like PHP array keys.

Comment by project member anti...@gmail.com, Dec 18, 2009

@tczoltan: for values it's already in this way. MSET values are binary safe, just make sure to use a client supporting MSET the right way (that is, using the multi bulk request protocol).

For keys, there is nothing preventing the user of binary safe keys in Redis, it's just that it is not tested well enough currently, also client-side support is needed (in order to use the multi bulk command protocol for every kind of request). This kind of stuff will be fixed in the next releases.

Comment by tczol...@gmail.com, Dec 20, 2009

thank you for your answer, perfect then! i'm preparing a presentation about Redis for my company and the keys being binary-safe is the only black point remained.

waiting for the next releases then :) thanks!

Comment by romf...@gmail.com, Feb 8, 2010

Is there a multi-bulk command as well? In the protocol specification I could only see multi-bulk replies. Is it the same, just the other way around?


Sign in to add a comment
Powered by Google Project Hosting