some day ago I committed code to support the multi bulk protocol to
issue queries to Redis.
The protocol is fully backward compatible, but now it's possible to
send commands this way:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
*3
$3
set
$6
foobar
$3
xyz
+OK
*2
$3
get
$6
foobar
$3
xyz
This basically means that all the parts are now binary safe. Using
this new protocol the keys itself are binary safe and can be any kind
of binary string, but probably it's a good idea to avoid to use this
feature as the usual commands are probably a little bit faster when
using the old protocol. I'm not sure about this...
What's important about this new feature is that allows to implement
MSET (atomic multi set of multiple keys/values) and commands to
manipulate hashes.
Another interesting property is that with the new protocol there is no
need to know if the command is a bulk command or not, so client
libraries targeting new versions of Redis may use this new protocol
when dealing with unknown commands. This will make this client
automagically capable of sending commands they don't know at all.
In the next week I'll continue implemeting MSET, and the Hashes. Then
I want to feature freeze to make this stable and release Redis 1.1
given that there will be enough new features to make a release:
integer encoding to save memory, MSET and support for hashes.
Cheers,
Salvatore
--
Salvatore 'antirez' Sanfilippo
http://invece.org
"Once you have something that grows faster than education grows,
you’re always going to get a pop culture.", Alan Kay
Hello,
this basically means we have to change the return value of KEYS! From
a simple string where every key is space separated, to a multi bulk
reply.
Btw I just committed MSET and MSETNX on Git. Client libs hacking
required in order to make this working in the real world.
The problem of escaping strings has been solved for a long time.
--
William <wmo...@masanjin.net>
> I guess it's broken and to try just by telnet was not wise :)
> I'll fix this problem tonight, that's in a few hours.
Ok, now it's fixed.
Cheers,
Salvatore
--
Update: tested some corner case, and pipelining when mixing old style
and new style protocol and all appears to be ok:
% echo -n "PING\r\n*3\r\n\$3\r\nset\r\n\$6\r\nfoobar\r\n\$3\r\nxyz\r\n*3\r\n\$3\r\nset\r\n\$6\r\nfoobar\r\n\$3\r\nxyz\r\nPING\r\n"
| nc localhost 6379
+PONG
+OK
+OK
+PONG
This does not mean it's rock solid code but is a good sign. I'll
continue to stress / debug / read it.
Hello Luca,
sorry, no documentation yet :( This is the minimal specification to
play with this commnads:
MSET key value ?key value? ?key value? ... ?key value?
Set all the keys to the specified values, atomically.
MSETNX does exactly the same, with "NX" semantic, but it is in my
opinion very interesting how it works:
if even a single key already exists, then no key at all will be set
(and 0 is returned instead of 1, like SETNX).
This makes a huge difference in building locking free algorithms, as
this ensures the ability to use SETNX to set a number of attributes of
the same object without race conditions. So for instance if two
clients will run the following two commands rougly at the same time:
a) SETNX foo:1000:name antirez foo:1000:phonenum 9403953405345 foo:1000:age 32
b) SETNX foo:1000:name mirka foo:1000:phonenum 1234567890 foo:1000:age 25
the foo:100:* fields will be either set all accordingly to a) or b). A
"mix" can't happen.
Andrei, thanks, now it's fixed.
Sorry for this bug, it was pretty stupid and I didn't tested this
command enough, from all the point of view.
I'll try to do a better work for the next times, it's not respectful
to provide code that contains a lot of stupid bugs that make early
adopters (the best kind of users) loose their time.
Monday I'll test the code more extensively.
Regards,
Salvatore
--
Salvatore 'antirez' Sanfilippo
Just added support for MSET and MSETNX using the new protocol to
redis-cli utility. So it should be a bit simpler to test the new
commands by hand.
Cheers,
Salvatore
--
Salvatore 'antirez' Sanfilippo