Skip to content

Commit

Permalink
added new HTML doc pages
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Dec 15, 2010
1 parent b9f7e9e commit 6674e3b
Show file tree
Hide file tree
Showing 12 changed files with 618 additions and 0 deletions.
39 changes: 39 additions & 0 deletions doc/BrpoplpushCommand.html
@@ -0,0 +1,39 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>BrpoplpushCommand: Contents</b><br>&nbsp;&nbsp;<a href="#BRPOPLPUSH _srckey_ _dstkey_ _timeout_ (Redis &gt;">BRPOPLPUSH _srckey_ _dstkey_ _timeout_ (Redis &gt;</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a>
</div>

<h1 class="wikiname">BrpoplpushCommand</h1>

<div class="summary">

</div>

<div class="narrow">

<h1><a name="BRPOPLPUSH _srckey_ _dstkey_ _timeout_ (Redis &gt;">BRPOPLPUSH _srckey_ _dstkey_ _timeout_ (Redis &gt;</a></h1> 2.1.8) =
<i>Time complexity: O(1)</i><blockquote>Blocking version of the <a href="RpoplpushCommand.html">RPOPLPUSH</a> command. Atomically removes and returnsthe last element (tail) of the source list at <i>srckey</i>, and as a side effect pushes the returned element in the head of the list at <i>dstkey</i>.</blockquote>
If the source list is empty, the client blocks until another client pushes against the source list. Of course in such a case the push operation against the destination list will be performed after the command unblocks detecting a push against the source list.<br/><br/>Note that the command returns an error if the target key already exists but is not a list. The error is delayed at the time the push operation is attempted, that is, immediately if the source list is not empty, or when the first push against the source list happens in the case the command would block.<br/><br/>The timeout value can be 0 or a positive integer value. When it is zero the command will block forever, until something is pushed against <i>srckey</i>. Otherwise the command will wait the specified number of seconds at max, returning an nil value when the timeout expires.<br/><br/>The source and destination of the list can be the same, having the effect of rotating the list. Please check <a href="RpoplpushCommand.html">RPOPLPUSH</a> for more information.<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Bulk reply</a>
</div>

</div>
</div>
</body>
</html>

39 changes: 39 additions & 0 deletions doc/GetbitCommand.html
@@ -0,0 +1,39 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>GetbitCommand: Contents</b><br>&nbsp;&nbsp;<a href="#GETBIT _key_ _offset_ (Redis &gt;">GETBIT _key_ _offset_ (Redis &gt;</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a>
</div>

<h1 class="wikiname">GetbitCommand</h1>

<div class="summary">

</div>

<div class="narrow">

<h1><a name="GETBIT _key_ _offset_ (Redis &gt;">GETBIT _key_ _offset_ (Redis &gt;</a></h1> 2.1.8) =
<i>Time complexity: O(1)</i><blockquote>Returns the bit value at <i>offset</i> in the string value stored at <i>key</i>.</blockquote>
When <i>offset</i> is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When <i>key</i> does not exist it is assumed to be an empty string, so <i>offset</i> is always out of range and the value is also assumed to be a contiguous space with 0 bits.<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Integer reply</a>, specifically: the bit value stored at <i>offset</i>.
</div>

</div>
</div>
</body>
</html>

40 changes: 40 additions & 0 deletions doc/HmgetCommand.html
@@ -0,0 +1,40 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>HmgetCommand: Contents</b><br>&nbsp;&nbsp;<a href="#HMGET _key_ _field1_ ... _fieldN_ (Redis &gt;">HMGET _key_ _field1_ ... _fieldN_ (Redis &gt;</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a>
</div>

<h1 class="wikiname">HmgetCommand</h1>

<div class="summary">

</div>

<div class="narrow">
&iuml;&raquo;&iquest;#sidebar <a href="HashCommandsSidebar.html">HashCommandsSidebar</a><h1><a name="HMGET _key_ _field1_ ... _fieldN_ (Redis &gt;">HMGET _key_ _field1_ ... _fieldN_ (Redis &gt;</a></h1> 1.3.10) =
<i>Time complexity: O(N) (with N being the number of fields)</i><blockquote>Retrieve the values associated to the specified <i>fields</i>.</blockquote>
<blockquote>If some of the specified <i>fields</i> do not exist, nil values are returned.Non existing keys are considered like empty hashes.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Multi Bulk Reply</a> specifically a list of all the values associated with the specified fields, in the same order of the request.

</div>

</div>
</div>
</body>
</html>

51 changes: 51 additions & 0 deletions doc/NonexistentCommands.html
@@ -0,0 +1,51 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>NonexistentCommands: Contents</b><br>&nbsp;&nbsp;<a href="#HGETSET">HGETSET</a><br>&nbsp;&nbsp;<a href="#SET with expire">SET with expire</a><br>&nbsp;&nbsp;<a href="#ZADDNX">ZADDNX</a>
</div>

<h1 class="wikiname">NonexistentCommands</h1>

<div class="summary">
A list of commands that don't exist in Redis, but can be accomplished in a different way.
</div>

<div class="narrow">

This is a list of commands that don't exist in Redis, but can be accomplished in a different way, usually by means of <a href="MultiExecCommand.html">WATCH/MULTI/EXEC</a>.<br/><br/>For better performance, you can pipeline multiple commands.<h1><a name="HGETSET">HGETSET</a></h1><a href="GetsetCommand.html">GETSET</a> for Hashes.<br/><br/><pre class="codeblock python" name="code">
WATCH foo
old_value = HGET foo field
MULTI
HSET foo field new_value
EXEC
</pre><h1><a name="SET with expire">SET with expire</a></h1>See <a href="SetexCommand.html">SETEX</a>.<h1><a name="ZADDNX">ZADDNX</a></h1>Add an element to a sorted set, only if the element doesn't already exist (by default, <a href="ZaddCommand.html">ZADD</a> would update the element's score if it already exists). <a href="http://groups.google.com/group/redis-db/browse_thread/thread/fc4c79d72e5bd346/6cdc07ecc36b81e7" target="_blank">See thread</a>.<br/><br/><pre class="codeblock python python" name="code">
WATCH foo
score = ZSCORE foo bar
IF score != NIL
MULTI
ZADD foo 1 bar
EXEC
ENDIF
</pre>
</div>

</div>
</div>
</body>
</html>

37 changes: 37 additions & 0 deletions doc/RedisCLI.html
@@ -0,0 +1,37 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>RedisCLI: Contents</b><br>&nbsp;&nbsp;<a href="#Redis CLI">Redis CLI</a>
</div>

<h1 class="wikiname">RedisCLI</h1>

<div class="summary">
Redis Command Line Interface
</div>

<div class="narrow">

<h1><a name="Redis CLI">Redis CLI</a></h1>
</div>

</div>
</div>
</body>
</html>

93 changes: 93 additions & 0 deletions doc/RedisPipelining.html
@@ -0,0 +1,93 @@

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">

<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>

<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>RedisPipelining: Contents</b><br>&nbsp;&nbsp;<a href="#Request/Response protocols and RTT">Request/Response protocols and RTT</a><br>&nbsp;&nbsp;<a href="#Redis Pipelining">Redis Pipelining</a><br>&nbsp;&nbsp;<a href="#Some benchmark">Some benchmark</a><br>&nbsp;&nbsp;<a href="#Pipelining VS other multi-commands">Pipelining VS other multi-commands</a>
</div>

<h1 class="wikiname">RedisPipelining</h1>

<div class="summary">

</div>

<div class="narrow">
<h1><a name="Request/Response protocols and RTT">Request/Response protocols and RTT</a></h1>
Redis is a TCP server using the client-server model and what is called a <b>Request/Response</b> protocol.<br/><br/>This means that usually a request is accomplished with the following steps:
<ul><li> The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.</li><li> The server processes the command and sends the response back to the server.</li></ul>So for instance a four commands sequence is something like this:
<ul><li> <b>Client:</b> INCR X</li><li> <b>Server:</b> 1</li><li> <b>Client:</b> INCR X</li><li> <b>Server:</b> 2</li><li> <b>Client:</b> INCR X</li><li> <b>Server:</b> 3</li><li> <b>Client:</b> INCR X</li><li> <b>Server:</b> 4</li></ul>Clients and Servers are connected via a networking link. Such a link can be very fast (a loopback interface) or very slow (a connection established over the internet with many hops between the two hosts). Whatever the network latency is, there is a time for the packets to travel from the client to the server, and back from the server to the client to carry the reply.<br/><br/>This time is called RTT (Round Trip Time). It is very easy to see how this can affect the performances when a client needs to perform many requests in a row (for instance adding many elements to the same list, or populating a database with many keys). For instance if the RTT time is 250 milliseconds (in the case of a very slow link over the internet), even if the server is able to process 100k requests per second, we'll be able to process at max four requests per second.<br/><br/>If the interface used is a loopback interface, the RTT is much shorter (for instance my host reports 0,044 milliseconds pinging 127.0.0.1), but it is still a lot if you need to perform many writes in a row.<br/><br/>Fortunately there is a way to improve this use cases.
<h1><a name="Redis Pipelining">Redis Pipelining</a></h1>
A Request/Response server can be implemented so that it is able to process new requests even if the client didn't already read the old responses. This way it is possible to send <b>multiple commands</b> to the server without waiting for the replies at all, and finally read the replies in a single step.<br/><br/>This is called pipelining, and is a technique widely in use since many decades. For instance many POP3 protocol implementations already supported this feature, dramatically speeding up the process of downloading new emails from the server.<br/><br/>Redis supports pipelining since the very early days, so whatever version you are running, you can use pipelining with Redis. This is an example using the raw netcat utility:
<pre class="codeblock python" name="code">
$ (echo -en &quot;PING\r\nPING\r\nPING\r\n&quot;; sleep 1) | nc localhost 6379
+PONG
+PONG
+PONG
</pre>
This time we are not paying the cost of RTT for every call, but just one time for the three commands.<br/><br/>To be very explicit, with pipelining the order of operations of our very first example will be the following:
<ul><li> <b>Client:</b> INCR X</li><li> <b>Client:</b> INCR X</li><li> <b>Client:</b> INCR X</li><li> <b>Client:</b> INCR X</li><li> <b>Server:</b> 1</li><li> <b>Server:</b> 2</li><li> <b>Server:</b> 3</li><li> <b>Server:</b> 4</li></ul><b>IMPORTANT NOTE</b>: while the client sends commands using pipelining, the server will be forced to queue the replies, using memory. So if you need to send many many commands with pipelining it's better to send this commands up to a given reasonable number, for instance 10k commands, read the replies, and send again other 10k commands and so forth. The speed will be nearly the same, but the additional memory used will be at max the amount needed to queue the replies for this 10k commands.
<h1><a name="Some benchmark">Some benchmark</a></h1>
In the following benchmark we'll use the Redis Ruby client, supporting pipelining, to test the speed improvement due to pipelining:
<pre class="codeblock python python" name="code">
require 'rubygems'
require 'redis'

def bench(descr)
start = Time.now
yield
puts &quot;#{descr} #{Time.now-start} seconds&quot;
end

def without_pipelining
r = Redis.new
10000.times {
r.ping
}
end

def with_pipelining
r = Redis.new
r.pipelined {
10000.times {
r.ping
}
}
end

bench(&quot;without pipelining&quot;) {
without_pipelining
}
bench(&quot;with pipelining&quot;) {
with_pipelining
}
</pre>
Running the above simple script will provide this figures in my Mac OS X system, running over the loopback interface, where pipelining will provide the smallest improvement as the RTT is already pretty low:
<pre class="codeblock python python python" name="code">
without pipelining 1.185238 seconds
with pipelining 0.250783 seconds
</pre>
As you can see using pipelining we improved the transfer by a factor of five.
<h1><a name="Pipelining VS other multi-commands">Pipelining VS other multi-commands</a></h1>
Often we get requests about adding new commands performing multiple operations in a single pass.
For instance there is no command to add multiple elements in a set. You need calling many times SADD.<br/><br/>With pipelining you can have performances near to an MSADD command, but at the same time we'll avoid bloating the Redis command set with too many commands. An additional advantage is that the version written using just SADD will be ready for a distributed environment (for instance Redis Cluster, that is in the process of being developed) just dropping the pipelining code.
</div>

</div>
</div>
</body>
</html>

0 comments on commit 6674e3b

Please sign in to comment.