2 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN">
5 <link type=
"text/css" rel=
"stylesheet" href=
"style.css" />
12 <img style=
"border:none" alt=
"Redis Documentation" src=
"redis.png">
16 <div id=
"pagecontent">
18 <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
19 <b>RpoplpushCommand: Contents
</b><br> <a href=
"#RPOPLPUSH _srckey_ _dstkey_ (Redis >">RPOPLPUSH _srckey_ _dstkey_ (Redis
></a><br> <a href=
"#Programming patterns: safe queues">Programming patterns: safe queues
</a><br> <a href=
"#Programming patterns: server-side O(N) list traversal">Programming patterns: server-side O(N) list traversal
</a><br> <a href=
"#Return value">Return value
</a><br> <a href=
"#See also">See also
</a>
22 <h1 class=
"wikiname">RpoplpushCommand
</h1>
29 <h1><a name=
"RPOPLPUSH _srckey_ _dstkey_ (Redis >">RPOPLPUSH _srckey_ _dstkey_ (Redis
></a></h1> 1.1) =
30 <i>Time complexity: O(
1)
</i><blockquote>Atomically return and remove the last (tail) element of the
<i>srckey
</i> list,and push the element as the first (head) element of the
<i>dstkey
</i> list. Forexample if the source list contains the elements
"a
",
"b
",
"c
" and thedestination list contains the elements
"foo
",
"bar
" after an RPOPLPUSH commandthe content of the two lists will be
"a
",
"b
" and
"c
",
"foo
",
"bar
".
</blockquote>
31 <blockquote>If the
<i>key
</i> does not exist or the list is already empty the specialvalue 'nil' is returned. If the
<i>srckey
</i> and
<i>dstkey
</i> are the same theoperation is equivalent to removing the last element from the list and pusingit as first element of the list, so it's a
"list rotation
" command.
</blockquote>
32 <h2><a name=
"Programming patterns: safe queues">Programming patterns: safe queues
</a></h2><blockquote>Redis lists are often used as queues in order to exchange messages betweendifferent programs. A program can add a message performing an
<a href=
"RpushCommand.html">LPUSH
</a> operationagainst a Redis list (we call this program a Producer), while another program(that we call Consumer) can process the messages performing an
<a href=
"LpopCommand.html">RPOP
</a> commandin order to start reading the messages from the oldest.
</blockquote>
33 <blockquote>Unfortunately if a Consumer crashes just after an
<a href=
"LpopCommand.html">RPOP
</a> operation the messagegets lost. RPOPLPUSH solves this problem since the returned message isadded to another
"backup
" list. The Consumer can later remove the messagefrom the backup list using the
<a href=
"LremCommand.html">LREM
</a> command when the message was correctlyprocessed.
</blockquote>
34 <blockquote>Another process, called Helper, can monitor the
"backup
" list to check fortimed out entries to repush against the main queue.
</blockquote>
35 <h2><a name=
"Programming patterns: server-side O(N) list traversal">Programming patterns: server-side O(N) list traversal
</a></h2><blockquote>Using RPOPPUSH with the same source and destination key a process canvisit all the elements of an N-elements List in O(N) without to transferthe full list from the server to the client in a single
<a href=
"LrangeCommand.html">LRANGE
</a> operation.Note that a process can traverse the list even while other processesare actively RPUSHing against the list, and still no element will be skipped.
</blockquote>
36 <h2><a name=
"Return value">Return value
</a></h2><a href=
"ReplyTypes.html">Bulk reply
</a><h2><a name=
"See also">See also
</a></h2>
37 <ul><li> <a href=
"RpushCommand.html">RPUSH
</a></li><li> <a href=
"RpushCommand.html">LPUSH
</a></li><li> <a href=
"LlenCommand.html">LLEN
</a></li><li> <a href=
"LrangeCommand.html">LRANGE
</a></li><li> <a href=
"LtrimCommand.html">LTRIM
</a></li><li> <a href=
"LindexCommand.html">LINDEX
</a></li><li> <a href=
"LsetCommand.html">LSET
</a></li><li> <a href=
"LremCommand.html">LREM
</a></li><li> <a href=
"LpopCommand.html">LPOP
</a></li><li> <a href=
"LpopCommand.html">RPOP
</a></li><li> <a href=
"RpoplpushCommand.html">RPOPLPUSH
</a></li></ul>