<i>Time complexity: O(1)</i><blockquote>Return a randomly selected key from the currently selected DB.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Return a randomly selected key from the currently selected DB.</blockquote>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Singe line reply</a>, specifically the randomly selected key or an empty string is the database is empty.<h2><aname="See also">See also</a></h2>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Singe line reply</a>, specifically the randomly selected key or an empty string is the database is empty.
<i>Time complexity: O(1)</i><blockquote>Atomically renames the key <i>oldkey</i> to <i>newkey</i>. If the source anddestination name are the same an error is returned. If <i>newkey</i>already exists it is overwritten.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Atomically renames the key <i>oldkey</i> to <i>newkey</i>. If the source anddestination name are the same an error is returned. If <i>newkey</i>already exists it is overwritten.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Rename <i>oldkey</i> into <i>newkey</i> but fails if the destination key <i>newkey</i> already exists.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Rename <i>oldkey</i> into <i>newkey</i> but fails if the destination key <i>newkey</i> already exists.</blockquote>
<b>RoadMap: Contents</b><br> <ahref="#Road Map (ROUGH DRAFT)">Road Map (ROUGH DRAFT)</a><br> <ahref="#Features added in past versions">Features added in past versions</a><br> <ahref="#1.1 / 1.2">1.1 / 1.2</a><br> <ahref="#0.x / 1.0">0.x / 1.0</a>
</div>
</div>
<h1class="wikiname">RoadMap</h1>
<h1class="wikiname">RoadMap</h1>
...
@@ -27,8 +27,8 @@
...
@@ -27,8 +27,8 @@
<divclass="narrow">
<divclass="narrow">
<h1><aname="Road Map (ROUGH DRAFT)">Road Map (ROUGH DRAFT)</a></h1>The up to date, raw Road Map for Redis is part of the source code, you can find it here: <ahref="http://github.com/antirez/redis/raw/master/TODO"target="_blank">http://github.com/antirez/redis/raw/master/TODO</a><h2><aname="TODO">TODO</a></h2>Add this information:<br/><br/><ahref="http://groups.google.com/group/redis-db/browse_thread/thread/95329fcbf7825169/70214fc6cfe01856?lnk=gst&q=roadmap#70214fc6cfe01856"target="_blank">http://groups.google.com/group/redis-db/browse_thread/thread/95329fcbf7825169/70214fc6cfe01856?lnk=gst&q=roadmap#70214fc6cfe01856</a><h2><aname="1.2">1.2</a></h2><br/><br/><ul><li><ahref="DataTypes.html">Hash data type</a>.</li></ul><blockquote></blockquote><h2><aname="1.1">1.1</a></h2><ul><li><ahref="DataTypes.html">Ordered Set (ZSET)</a></li><li><ahref="MultiBulkCommands.html">Multibulk Commands</a></li><li> In memory integer encoding of <ahref="DataTypes.html">integers</a>. Memory saving of 20% or more with datasets using high number of integer IDs. </li><li> Enhanced <ahref="ExpireCommand.html">EXPIRE</a> algorithm.</li></ul>
<h1><aname="Road Map (ROUGH DRAFT)">Road Map (ROUGH DRAFT)</a></h1>The up to date, raw Road Map for Redis is part of the source code, you can find it here: <ahref="http://github.com/antirez/redis/raw/master/TODO"target="_blank">http://github.com/antirez/redis/raw/master/TODO</a><h2><aname="Features added in past versions">Features added in past versions</a></h2><h2><aname="1.1 / 1.2">1.1 / 1.2</a></h2><ul><li><ahref="DataTypes.html">Ordered Set (ZSET)</a></li><li><ahref="MultiBulkCommands.html">Multibulk Commands</a></li><li> In memory integer encoding of <ahref="DataTypes.html">integers</a>. Memory saving of 20% or more with datasets using high number of integer IDs. </li><li> Enhanced <ahref="ExpireCommand.html">EXPIRE</a> algorithm.</li></ul>
<h2><aname="1.0">1.0</a></h2><ul><li> TODO: Add 1.0 Features. This is important for clarity in <ahref="SupportedLanguages.html">SupportedLanguages</a></li></ul>
<h2><aname="0.x / 1.0">0.x / 1.0</a></h2><ul><li> TODO: Add 1.0 Features. This is important for clarity in <ahref="SupportedLanguages.html">SupportedLanguages</a></li></ul>
<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>
<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>
<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>
<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>
<h2><aname="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 <ahref="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 <ahref="LpopCommand.html">RPOP</a> commandin order to start reading the messages from the oldest.</blockquote>
<h2><aname="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 <ahref="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 <ahref="LpopCommand.html">RPOP</a> commandin order to start reading the messages from the oldest.</blockquote>
<blockquote>Unfortunately if a Consumer crashes just after an <ahref="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 <ahref="LremCommand.html">LREM</a> command when the message was correctlyprocessed.</blockquote>
<blockquote>Unfortunately if a Consumer crashes just after an <ahref="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 <ahref="LremCommand.html">LREM</a> command when the message was correctlyprocessed.</blockquote>
<blockquote>Another process, called Helper, can monitor the "backup" list to check fortimed out entries to repush against the main queue.</blockquote>
<blockquote>Another process, called Helper, can monitor the "backup" list to check fortimed out entries to repush against the main queue.</blockquote>
<h2><aname="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 <ahref="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>
<h2><aname="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 <ahref="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>
<i>Time complexity: O(1)</i><blockquote>Add the <i>string</i> value to the head (RPUSH) or tail (LPUSH) of the liststored at <i>key</i>. If the key does not exist an empty list is created just beforethe append operation. If the key exists but is not a List an erroris returned.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Add the <i>string</i> value to the head (RPUSH) or tail (LPUSH) of the liststored at <i>key</i>. If the key does not exist an empty list is created just beforethe append operation. If the key exists but is not a List an erroris returned.</blockquote>
<i>Time complexity O(1)</i><blockquote>Add the specified <i>member</i> to the set value stored at <i>key</i>. If <i>member</i>is already a member of the set no operation is performed. If <i>key</i>does not exist a new set with the specified <i>member</i> as sole member iscrated. If the key exists but does not hold a set value an error isreturned.</blockquote>
<i>Time complexity O(1)</i><blockquote>Add the specified <i>member</i> to the set value stored at <i>key</i>. If <i>member</i>is already a member of the set no operation is performed. If <i>key</i>does not exist a new set with the specified <i>member</i> as sole member iscrated. If the key exists but does not hold a set value an error isreturned.</blockquote>
<blockquote>Save the DB on disk. The server hangs while the saving is notcompleted, no connection is served in the meanwhile. An OK codeis returned when the DB was fully stored in disk.</blockquote>
<blockquote>Save the DB on disk. The server hangs while the saving is notcompleted, no connection is served in the meanwhile. An OK codeis returned when the DB was fully stored in disk.</blockquote>
<i>Time complexity O(1)</i><blockquote>Return the set cardinality (number of elements). If the <i>key</i> does notexist 0 is returned, like for empty sets.</blockquote>
<i>Time complexity O(1)</i><blockquote>Return the set cardinality (number of elements). If the <i>key</i> does notexist 0 is returned, like for empty sets.</blockquote>
<i>Time complexity O(N) with N being the total number of elements of all the sets</i><blockquote>Return the members of a set resulting from the difference between the firstset provided and all the successive sets. Example:</blockquote>
<i>Time complexity O(N) with N being the total number of elements of all the sets</i><blockquote>Return the members of a set resulting from the difference between the firstset provided and all the successive sets. Example:</blockquote>
<preclass="codeblock python"name="code">
<preclass="codeblock python"name="code">
key1 = x,a,b,c
key1 = x,a,b,c
...
@@ -34,8 +34,8 @@ key2 = c
...
@@ -34,8 +34,8 @@ key2 = c
key3 = a,d
key3 = a,d
SDIFF key1,key2,key3 => x,b
SDIFF key1,key2,key3 => x,b
</pre><blockquote>Non existing keys are considered like empty sets.</blockquote>
</pre><blockquote>Non existing keys are considered like empty sets.</blockquote>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.<h2><aname="See also">See also</a></h2>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.
<i>Time complexity O(N) where N is the total number of elements in all the provided sets</i><blockquote>This commnad works exactly like SDIFF but instead of being returned the resulting set is sotred in <i>dstkey</i>.</blockquote>
<i>Time complexity O(N) where N is the total number of elements in all the provided sets</i><blockquote>This commnad works exactly like SDIFF but instead of being returned the resulting set is sotred in <i>dstkey</i>.</blockquote>
<blockquote>Select the DB with having the specified zero-based numeric index.For default every new client connection is automatically selectedto DB 0.</blockquote>
<blockquote>Select the DB with having the specified zero-based numeric index.For default every new client connection is automatically selectedto DB 0.</blockquote>
<i>Time complexity: O(1)</i><blockquote>Set the string <i>value</i> as value of the <i>key</i>.The string can't be longer than 1073741824 bytes (1 GB).</blockquote>
<i>Time complexity: O(1)</i><blockquote>Set the string <i>value</i> as value of the <i>key</i>.The string can't be longer than 1073741824 bytes (1 GB).</blockquote>
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>SetCommandsSidebar: Contents</b>
</div>
<h1class="wikiname">SetCommandsSidebar</h1>
<divclass="summary">
</div>
<divclass="narrow">
== Set Commands ==<br/><br/><ul><li><ahref="SaddCommand.html">SADD</a></li><li><ahref="SremCommand.html">SREM</a></li><li><ahref="SpopCommand.html">SPOP</a></li><li><ahref="SmoveCommand.html">SMOVE</a></li><li><ahref="ScardCommand.html">SCARD</a></li><li><ahref="SismemberCommand.html">SISMEMBER</a></li><li><ahref="SinterCommand.html">SINTER</a></li><li><ahref="SinterstoreCommand.html">SINTERSTORE</a></li><li><ahref="SunionCommand.html">SUNION</a></li><li><ahref="SunionstoreCommand.html">SUNIONSTORE</a></li><li><ahref="SdiffCommand.html">SDIFF</a></li><li><ahref="SdiffstoreCommand.html">SDIFFSTORE</a></li><li><ahref="SmembersCommand.html">SMEMBERS</a></li><li><ahref="SrandmemberCommand.html">SRANDMEMBER</a></li><li><ahref="SortCommand.html">SORT</a></li></ul>
<i>Time complexity: O(1)</i><blockquote>SETNX works exactly like <ahref="SetCommand.html">SET</a> with the only difference thatif the key already exists no operation is performed.SETNX actually means "SET if Not eXists".</blockquote>
<i>Time complexity: O(1)</i><blockquote>SETNX works exactly like <ahref="SetCommand.html">SET</a> with the only difference thatif the key already exists no operation is performed.SETNX actually means "SET if Not eXists".</blockquote>
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
<b>Sets: Contents</b><br> <ahref="#Redis Set Type">Redis Set Type</a><br> <ahref="#Implementation details">Implementation details</a>
</div>
<h1class="wikiname">Sets</h1>
<divclass="summary">
</div>
<divclass="narrow">
#sidebar <ahref="SetCommandsSidebar.html">SetCommandsSidebar</a><h1><aname="Redis Set Type">Redis Set Type</a></h1>Redis Sets are unordered collections of <ahref="Stings.html">Redis Strings</a>. It's possible to add, remove, and test for existence of members in O(1).<br/><br/>Redis Sets have the desirable property of not allowing repeated members. Adding the same element multiple times will result in a set having a single copy of this element. Practically speaking this means that adding an members does not require a "check if exists then add" operation.<br/><br/>Commands operating on sets try to make a good use of the return value in order to signal the application about previous existence of members. For instance the <ahref="SaddCommand.html">SADD</a> command will return 1 if the element added was not already a member of the set, otherwise will return 0.<br/><br/>The max number of members in a set is 232-1 (4294967295, more than 4 billion of members per set).<br/><br/>Redis Sets support a wide range of operations, like union, intersection, difference. Intersection is optimized in order to perform the smallest number of lookups. For instance if you try to intersect a 10000 members set with a 2 members set Redis will iterate the 2 members set testing for members existence in the other set, performing 2 lookups instead of 10000.<h1><aname="Implementation details">Implementation details</a></h1>Redis Sets are implemented using hash tables, so adding, removing and testing for members is O(1) in the average. The hash table will automatically resize when new elements are added or removed into a Set.<br/><br/>The hash table resizing is a blocking operation performed synchronously so working with huge sets (consisting of many millions of elements) care should be taken when mass-inserting a very big amount of elements in a Set while other clients are querying Redis at high speed.<br/><br/>It is possible that in the near future Redis will switch to skip lists (already used in sorted sets) in order to avoid such a problem.
<blockquote>Stop all the clients, save the DB, then quit the server. This commandsmakes sure that the DB is switched off without the lost of any data.This is not guaranteed if the client uses simply "SAVE" and then"QUIT" because other clients may alter the DB data between the twocommands.</blockquote>
<blockquote>Stop all the clients, save the DB, then quit the server. This commandsmakes sure that the DB is switched off without the lost of any data.This is not guaranteed if the client uses simply "SAVE" and then"QUIT" because other clients may alter the DB data between the twocommands.</blockquote>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Status code reply</a> on error. On success nothing is returned since the server quits and the connection is closed.<h2><aname="See also">See also</a></h2>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Status code reply</a> on error. On success nothing is returned since the server quits and the connection is closed.
<i>Time complexity O(N<b>M) worst case where N is the cardinality of the smallest set and M the number of sets_<br/><br/><blockquote>Return the members of a set resulting from the intersection of all thesets hold at the specified keys. Like in LRANGE the result is sent tothe client as a multi-bulk reply (see the protocol specification formore information). If just a single key is specified, then this commandproduces the same result as SMEMBERS. Actually SMEMBERS is just syntaxsugar for SINTERSECT.</blockquote>
<i>Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets</i><blockquote>Return the members of a set resulting from the intersection of all thesets hold at the specified keys. Like in LRANGE the result is sent tothe client as a multi-bulk reply (see the protocol specification formore information). If just a single key is specified, then this commandproduces the same result as SMEMBERS. Actually SMEMBERS is just syntaxsugar for SINTERSECT.</blockquote>
<blockquote>Non existing keys are considered like empty sets, so if one of the keys ismissing an empty set is returned (since the intersection with an emptyset always is an empty set).</blockquote>
<blockquote>Non existing keys are considered like empty sets, so if one of the keys ismissing an empty set is returned (since the intersection with an emptyset always is an empty set).</blockquote>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.<h2><aname="See also">See also</a></h2>
<h2><aname="Return value">Return value</a></h2><ahref="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.
<i>Time complexity O(N<b>M) worst case where N is the cardinality of the smallest set and M the number of sets_<br/><br/><blockquote>This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as _dstkey_.</blockquote>
<i>Time complexity O(NM) worst case where N is the cardinality of the smallest set and M the number of sets</i><blockquote>This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as <i>dstkey</i>.</blockquote>