@@ -81,22 +81,21 @@ our key was added without problems. Actually SET can never fail but
...
@@ -81,22 +81,21 @@ our key was added without problems. Actually SET can never fail but
the "+OK" sent lets us know that the server received everything and
the "+OK" sent lets us know that the server received everything and
the command was actually executed.<br/><br/>Let's try to get the key content now:<br/><br/><preclass="codeblock python python"name="code">
the command was actually executed.<br/><br/>Let's try to get the key content now:<br/><br/><preclass="codeblock python python"name="code">
GET foo
GET foo
3
$3
bar
bar
</pre>Ok that's very similar to 'set', just the other way around. We sent "get foo",
</pre>Ok that's very similar to 'set', just the other way around. We sent "get foo",
the server replied with a first line that is just a number of bytes the value
the server replied with a first line that is just the $ character follwed by
stored at key contained, followed by the actual bytes. Again "\r\n" are appended
the number of bytes the value stored at key contained, followed by the actual
both to the bytes count and the actual data.<br/><br/>What about requesting a non existing key?<br/><br/><preclass="codeblock python python python"name="code">
bytes. Again "\r\n" are appended both to the bytes count and the actual data. In Redis slang this is called a bulk reply.<br/><br/>What about requesting a non existing key?<br/><br/><preclass="codeblock python python python"name="code">
GET blabla
GET blabla
nil
$-1
</pre>When the key does not exist instead of the length just the "nil" string is sent.
</pre>When the key does not exist instead of the length, just the "$-1" string is sent. Since a -1 length of a bulk reply has no meaning it is used in order to specifiy a 'nil' value and distinguish it from a zero length value. Another way to check if a given key exists or not is indeed the EXISTS command:<br/><br/><preclass="codeblock python python python python"name="code">
Another way to check if a given key exists or not is indeed the EXISTS command:<br/><br/><preclass="codeblock python python python python"name="code">
EXISTS nokey
EXISTS nokey
0
:0
EXISTS foo
EXISTS foo
1
:1
</pre>As you can see the server replied '0' the first time since 'nokey' does not
</pre>As you can see the server replied ':0' the first time since 'nokey' does not
exist, and '1' for 'foo', a key that actually exists.<br/><br/>Ok... now you know the basics, read the <ahref="CommandReference.html">REDIS COMMAND REFERENCE</a> section to
exist, and ':1' for 'foo', a key that actually exists. Replies starting with the colon character are integer reply.<br/><br/>Ok... now you know the basics, read the <ahref="CommandReference.html">REDIS COMMAND REFERENCE</a> section to
learn all the commands supported by Redis and the <ahref="ProtocolSpecification.html">PROTOCOL SPECIFICATION</a>
learn all the commands supported by Redis and the <ahref="ProtocolSpecification.html">PROTOCOL SPECIFICATION</a>
section for more details about the protocol used if you plan to implement one
section for more details about the protocol used if you plan to implement one
for a language missing a decent client implementation.<h1><aname="License">License</a></h1>Redis is released under the BSD license. See the COPYING file for more information.<h1><aname="Credits">Credits</a></h1>Redis is written and maintained by Salvatore Sanfilippo, Aka 'antirez'.<br/><br/>Enjoy,
for a language missing a decent client implementation.<h1><aname="License">License</a></h1>Redis is released under the BSD license. See the COPYING file for more information.<h1><aname="Credits">Credits</a></h1>Redis is written and maintained by Salvatore Sanfilippo, Aka 'antirez'.<br/><br/>Enjoy,