|
MsetCommand
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 valueStatus code reply Basically +OK as MSET can't fail MSETNX Return valueInteger reply, specifically: 1 if the all the keys were set 0 if no key was set (at least one key already existed) | |
► Sign in to add a comment
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.
@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.
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!
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?