SMOVE command implemented

This commit is contained in:
antirez 2009-04-28 20:36:08 +02:00
parent bb0b03a3d7
commit a4460ef43f
16 changed files with 96 additions and 11 deletions

View File

@ -1,3 +1,5 @@
2009-04-28 less CPU usage in command parsing, case insensitive config directives
2009-04-28 GETSET command doc added
2009-04-28 GETSET tests
2009-04-28 GETSET implemented
2009-04-27 ability to specify a different file name for the DB

1
TODO
View File

@ -1,5 +1,6 @@
BEFORE REDIS 1.0.0-rc1
- SMOVE _key1_ _key2_ _ele_. Pop an element form _key1_ and push (SADD or LPUSH) it nto _key2_.
- What happens if the saving child gets killed instead to end normally? Handle this.
- Make sinterstore / unionstore / sdiffstore returning the cardinality of the resulting set.
- Remove max number of args limit

View File

@ -30,7 +30,7 @@
<h2><a name="Commands operating on string values">Commands operating on string values</a></h2><ul><li> <a href="SetCommand.html">SET</a> <i>key</i> <i>value</i> <code name="code" class="python">set a key to a string value</code></li><li> <a href="GetCommand.html">GET</a> <i>key</i> <code name="code" class="python">return the string value of the key</code></li><li> <a href="GetsetCommand.html">GETSET</a> <i>key</i> <i>value</i> <code name="code" class="python">set a key to a string returning the old value of the key</code></li><li> <a href="MgetCommand.html">MGET</a> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">multi-get, return the strings values of the keys</code></li><li> <a href="SetnxCommand.html">SETNX</a> <i>key</i> <i>value</i> <code name="code" class="python">set a key to a string value if the key does not exist</code></li><li> <a href="IncrCommand.html">INCR</a> <i>key</i> <code name="code" class="python">increment the integer value of key</code></li><li> <a href="IncrCommand.html">INCRBY</a> <i>key</i> <i>integer</i><code name="code" class="python"> increment the integer value of key by integer</code></li><li> <a href="IncrCommand.html">DECR</a> <i>key</i> <code name="code" class="python">decrement the integer value of key</code></li><li> <a href="IncrCommand.html">DECRBY</a> <i>key</i> <i>integer</i> <code name="code" class="python">decrement the integer value of key by integer</code></li><li> <a href="ExistsCommand.html">EXISTS</a> <i>key</i> <code name="code" class="python">test if a key exists</code></li><li> <a href="DelCommand.html">DEL</a> <i>key</i> <code name="code" class="python">delete a key</code></li><li> <a href="TypeCommand.html">TYPE</a> <i>key</i> <code name="code" class="python">return the type of the value stored at key</code></li></ul>
<h2><a name="Commands operating on the key space">Commands operating on the key space</a></h2><ul><li> <a href="KeysCommand.html">KEYS</a> <i>pattern</i> <code name="code" class="python">return all the keys matching a given pattern</code></li><li> <a href="RandomkeyCommand.html">RANDOMKEY</a> <code name="code" class="python">return a random key from the key space</code></li><li> <a href="RenameCommand.html">RENAME</a> <i>oldname</i> <i>newname</i> <code name="code" class="python">rename the old key in the new one, destroing the newname key if it already exists</code></li><li> <a href="RenamenxCommand.html">RENAMENX</a> <i>oldname</i> <i>newname</i> <code name="code" class="python">rename the old key in the new one, if the newname key does not already exist</code></li><li> <a href="DbsizeCommand.html">DBSIZE</a> <code name="code" class="python">return the number of keys in the current db</code></li><li> <a href="ExpireCommand.html">EXPIRE</a> <code name="code" class="python">set a time to live in seconds on a key</code></li></ul>
<h2><a name="Commands operating on lists">Commands operating on lists</a></h2><ul><li> <a href="RpushCommand.html">RPUSH</a> <i>key</i> <i>value</i> <code name="code" class="python">Append an element to the tail of the List value at key</code></li><li> <a href="RpushCommand.html">LPUSH</a> <i>key</i> <i>value</i> <code name="code" class="python">Append an element to the head of the List value at key</code></li><li> <a href="LlenCommand.html">LLEN</a> <i>key</i> <code name="code" class="python">Return the length of the List value at key</code></li><li> <a href="LrangeCommand.html">LRANGE</a> <i>key</i> <i>start</i> <i>end</i> <code name="code" class="python">Return a range of elements from the List at key</code></li><li> <a href="LtrimCommand.html">LTRIM</a> <i>key</i> <i>start</i> <i>end</i> <code name="code" class="python">Trim the list at key to the specified range of elements</code></li><li> <a href="LindexCommand.html">LINDEX</a> <i>key</i> <i>index</i> <code name="code" class="python">Return the element at index position from the List at key</code></li><li> <a href="LsetCommand.html">LSET</a> <i>key</i> <i>index</i> <i>value</i> <code name="code" class="python">Set a new value as the element at index position of the List at key</code></li><li> <a href="LremCommand.html">LREM</a> <i>key</i> <i>count</i> <i>value</i> <code name="code" class="python">Remove the first-N, last-N, or all the elements matching value from the List at key</code></li><li> <a href="LpopCommand.html">LPOP</a> <i>key</i> <code name="code" class="python">Return and remove (atomically) the first element of the List at key</code></li><li> <a href="LpopCommand.html">RPOP</a> <i>key</i> <code name="code" class="python">Return and remove (atomically) the last element of the List at key</code></li></ul>
<h2><a name="Commands operating on sets">Commands operating on sets</a></h2><ul><li> <a href="SaddCommand.html">SADD</a> <i>key</i> <i>member</i> <code name="code" class="python">Add the specified member to the Set value at key</code></li><li> <a href="SremCommand.html">SREM</a> <i>key</i> <i>member</i> <code name="code" class="python">Remove the specified member from the Set value at key</code></li><li> <a href="ScardCommand.html">SCARD</a> <i>key</i> <code name="code" class="python">Return the number of elements (the cardinality) of the Set at key</code></li><li> <a href="SismemberCommand.html">SISMEMBER</a> <i>key</i> <i>member</i> <code name="code" class="python">Test if the specified value is a member of the Set at key</code></li><li> <a href="SinterCommand.html">SINTER</a> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Return the intersection between the Sets stored at key1, key2, ..., keyN</code></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a> <i>dstkey</i> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Compute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey</code></li><li> <a href="SunionCommand.html">SUNION</a> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Return the union between the Sets stored at key1, key2, ..., keyN</code></li><li> <a href="SunionstoreCommand.html">SUNIONSTORE</a> <i>dstkey</i> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Compute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey</code></li><li> <a href="SmembersCommand.html">SMEMBERS</a> <i>key</i> <code name="code" class="python">Return all the members of the Set value at key</code></li></ul>
<h2><a name="Commands operating on sets">Commands operating on sets</a></h2><ul><li> <a href="SaddCommand.html">SADD</a> <i>key</i> <i>member</i> <code name="code" class="python">Add the specified member to the Set value at key</code></li><li> <a href="SremCommand.html">SREM</a> <i>key</i> <i>member</i> <code name="code" class="python">Remove the specified member from the Set value at key</code></li><li> <a href="SmoveCommand.html">SMOVE</a> <i>srckey</i> <i>dstkey</i> <i>member</i> <code name="code" class="python">Move the specified member from one Set to another atomically</code></li><li> <a href="ScardCommand.html">SCARD</a> <i>key</i> <code name="code" class="python">Return the number of elements (the cardinality) of the Set at key</code></li><li> <a href="SismemberCommand.html">SISMEMBER</a> <i>key</i> <i>member</i> <code name="code" class="python">Test if the specified value is a member of the Set at key</code></li><li> <a href="SinterCommand.html">SINTER</a> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Return the intersection between the Sets stored at key1, key2, ..., keyN</code></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a> <i>dstkey</i> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Compute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey</code></li><li> <a href="SunionCommand.html">SUNION</a> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Return the union between the Sets stored at key1, key2, ..., keyN</code></li><li> <a href="SunionstoreCommand.html">SUNIONSTORE</a> <i>dstkey</i> <i>key1</i> <i>key2</i> ... <i>keyN</i> <code name="code" class="python">Compute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey</code></li><li> <a href="SmembersCommand.html">SMEMBERS</a> <i>key</i> <code name="code" class="python">Return all the members of the Set value at key</code></li></ul>
<h2><a name="Multiple databases handling commands">Multiple databases handling commands</a></h2><ul><li> <a href="SelectCommand.html">SELECT</a> <i>index</i> <code name="code" class="python">Select the DB having the specified index</code></li><li> <a href="MoveCommand.html">MOVE</a> <i>key</i> <i>dbindex</i> <code name="code" class="python">Move the key from the currently selected DB to the DB having as index dbindex</code></li><li> <a href="FlushdbCommand.html">FLUSHDB</a> <code name="code" class="python">Remove all the keys of the currently selected DB</code></li><li> <a href="FlushallCommand.html">FLUSHALL</a> <code name="code" class="python">Remove all the keys from all the databases</code></li></ul>
<h2><a name="Sorting">Sorting</a></h2><ul><li> <a href="SortCommand.html">SORT</a> <i>key</i> BY <i>pattern</i> LIMIT <i>start</i> <i>end</i> GET <i>pattern</i> ASC|DESC ALPHA <code name="code" class="python">Sort a Set or a List accordingly to the specified parameters</code></li></ul>
<h2><a name="Persistence control commands">Persistence control commands</a></h2><ul><li> <a href="SaveCommand.html">SAVE</a> <code name="code" class="python">Synchronously save the DB on disk</code></li><li> <a href="BgsaveCommand.html">BGSAVE</a> <code name="code" class="python">Asynchronously save the DB on disk</code></li><li> <a href="LastsaveCommand.html">LASTSAVE</a> <code name="code" class="python">Return the UNIX time stamp of the last successfully saving of the dataset on disk</code></li><li> <a href="ShutdownCommand.html">SHUTDOWN</a> <code name="code" class="python">Synchronously save the DB on disk, then shutdown the server</code></li></ul>

View File

@ -32,7 +32,7 @@
1 if the new element was added
0 if the new element was already a member of the set
</pre><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -31,7 +31,7 @@
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Integer reply</a>, specifically:<br/><br/><pre class="codeblock python" name="code">
the cardinality (number of elements) of the set as an integer.
</pre><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
<ul><li> <a href="SaddCommand.html">SADD</a></li><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -30,7 +30,7 @@
<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 SELEMENTS. Actually SELEMENTS 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>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.<h2><a name="See also">See also</a></h2>
<blockquote>* <a href="SremCommand.html">SREM</a>* <a href="SismemberCommand.html">SISMEMBER</a>* <a href="ScardCommand.html">SCARD</a>* <a href="SmembersCommand.html">SMEMBERS</a>* <a href="SinterstoreCommand.html">SINTERSTORE</a>* <a href="SunionCommand.html">SUNION</a>* <a href="SunionstoreCommand.html">SUNIONSTORE</a></blockquote></b></i>
<blockquote>* <a href="SaddCommand.html">SADD</a>* <a href="SremCommand.html">SREM</a>* <a href="SismemberCommand.html">SISMEMBER</a>* <a href="ScardCommand.html">SCARD</a>* <a href="SmembersCommand.html">SMEMBERS</a>* <a href="SinterstoreCommand.html">SINTERSTORE</a>* <a href="SunionCommand.html">SUNION</a>* <a href="SunionstoreCommand.html">SUNIONSTORE</a>* <a href="SmoveCommand.html">SMOVE</a></blockquote></b></i>
</div>
</div>

View File

@ -29,7 +29,7 @@
<h1><a name="SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_">SINTERSTORE _dstkey_ _key1_ _key2_ ... _keyN_</a></h1>
<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>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Status code reply</a><h2><a name="See also">See also</a></h2>
<blockquote>* <a href="SremCommand.html">SREM</a>* <a href="SismemberCommand.html">SISMEMBER</a>* <a href="ScardCommand.html">SCARD</a>* <a href="SmembersCommand.html">SMEMBERS</a>* <a href="SinterCommand.html">SINTER</a>* <a href="SinterstoreCommand.html">SINTERSTORE</a></blockquote></b></i>
<blockquote>* <a href="SaddCommand.html">SADD</a>* <a href="SremCommand.html">SREM</a>* <a href="SismemberCommand.html">SISMEMBER</a>* <a href="ScardCommand.html">SCARD</a>* <a href="SmembersCommand.html">SMEMBERS</a>* <a href="SinterCommand.html">SINTER</a>* <a href="SinterstoreCommand.html">SINTERSTORE</a>* <a href="SmoveCommand.html">SMOVE</a></blockquote></b></i>
</div>
</div>

View File

@ -32,7 +32,7 @@
1 if the element is a member of the set
0 if the element is not a member of the set OR if the key does not exist
</pre><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
<ul><li> <a href="SaddCommand.html">SADD</a></li><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -29,7 +29,7 @@
<h1><a name="SMEMBERS _key_">SMEMBERS _key_</a></h1>
<i>Time complexity O(N)</i><blockquote>Return all the members (elements) of the set value stored at <i>key</i>. Thisis just syntax glue for <a href="SintersectCommand.html">SINTERSECT</a>.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Multi bulk reply</a><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
<ul><li> <a href="SaddCommand.html">SADD</a></li><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

44
doc/SmoveCommand.html Normal file
View File

@ -0,0 +1,44 @@
<!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>SmoveCommand: Contents</b><br>&nbsp;&nbsp;<a href="#SMOVE _srckey_ _dstkey_ _member_">SMOVE _srckey_ _dstkey_ _member_</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Return value">Return value</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#See also">See also</a>
</div>
<h1 class="wikiname">SmoveCommand</h1>
<div class="summary">
</div>
<div class="narrow">
<h1><a name="SMOVE _srckey_ _dstkey_ _member_">SMOVE _srckey_ _dstkey_ _member_</a></h1>
<i>Time complexity O(1)</i><blockquote>Move the specifided <i>member</i> from the set at <i>srckey</i> to the set at <i>dstkey</i>.This operation is atomic, in every given moment the element will appear tobe in the source or destination set for accessing clients.</blockquote>
<blockquote>If the source set does not exist or does not contain the specified elementno operation is performed and zero is returned, otherwise the element isremoved from the source set and added to the destination set. On successone is returned, even if the element was already present in the destionationset.</blockquote>
<blockquote>An error is raised if the source or destination keys contain a non Set value.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Integer reply</a>, specifically:<br/><br/><pre class="codeblock python" name="code">
1 if the element was moved
0 if the element was not found on the first set and no operation was performed
</pre><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SaddCommand.html">SADD</a></li><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
</div>
</div>
</div>
</body>
</html>

View File

@ -50,7 +50,7 @@ SORT mylist BY weight_*
SORT mylist BY weight_* GET object_*
</pre><blockquote>Note that GET can be used multiple times in order to get more keys forevery element of the original List or Set sorted.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Multi bulk reply</a>, specifically a list of sorted elements.<h2><a name="See Also">See Also</a></h2>
<ul><li> <a href="SinterCommand.html">SINTER</a></li></ul>
<ul><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SunionCommand.html">SUNION</a></li></ul>
</div>
</div>

View File

@ -32,7 +32,7 @@
1 if the new element was removed
0 if the new element was not a member of the set
</pre><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li></ul>
<ul><li> <a href="SaddCommand.html">SADD</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -30,7 +30,7 @@
<i>Time complexity O(N) where N is the total number of elements in all the provided sets</i><blockquote>Return the members of a set resulting from the union 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 SELEMENTS.</blockquote>
<blockquote>Non existing keys are considered like empty sets.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Multi bulk reply</a>, specifically the list of common elements.<h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SunionstoreCommand.html">SUNIONSTORE</a></li></ul>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SunionstoreCommand.html">SUNIONSTORE</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -29,7 +29,7 @@
<h1><a name="SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_">SUNIONSTORE _dstkey_ _key1_ _key2_ ... _keyN_</a></h1>
<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 SUNION but instead of being returned the resulting set is sotred as <i>dstkey</i>.</blockquote>
<h2><a name="Return value">Return value</a></h2><a href="ReplyTypes.html">Status code reply</a><h2><a name="See also">See also</a></h2>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SunionCommand.html">SUNION</a></li></ul>
<ul><li> <a href="SremCommand.html">SREM</a></li><li> <a href="SismemberCommand.html">SISMEMBER</a></li><li> <a href="ScardCommand.html">SCARD</a></li><li> <a href="SmembersCommand.html">SMEMBERS</a></li><li> <a href="SinterCommand.html">SINTER</a></li><li> <a href="SinterstoreCommand.html">SINTERSTORE</a></li><li> <a href="SunionCommand.html">SUNION</a></li><li> <a href="SmoveCommand.html">SMOVE</a></li></ul>
</div>
</div>

View File

@ -76,6 +76,7 @@ static struct redisCommand cmdTable[] = {
{"lrem",4,REDIS_CMD_BULK},
{"sadd",3,REDIS_CMD_BULK},
{"srem",3,REDIS_CMD_BULK},
{"smove",4,REDIS_CMD_BULK},
{"sismember",3,REDIS_CMD_BULK},
{"scard",2,REDIS_CMD_INLINE},
{"sinter",-2,REDIS_CMD_INLINE},

37
redis.c
View File

@ -341,6 +341,7 @@ static void typeCommand(redisClient *c);
static void lsetCommand(redisClient *c);
static void saddCommand(redisClient *c);
static void sremCommand(redisClient *c);
static void smoveCommand(redisClient *c);
static void sismemberCommand(redisClient *c);
static void scardCommand(redisClient *c);
static void sinterCommand(redisClient *c);
@ -383,6 +384,7 @@ static struct redisCommand cmdTable[] = {
{"lrem",lremCommand,4,REDIS_CMD_BULK},
{"sadd",saddCommand,3,REDIS_CMD_BULK},
{"srem",sremCommand,3,REDIS_CMD_BULK},
{"smove",smoveCommand,4,REDIS_CMD_BULK},
{"sismember",sismemberCommand,3,REDIS_CMD_BULK},
{"scard",scardCommand,2,REDIS_CMD_INLINE},
{"sinter",sinterCommand,-2,REDIS_CMD_INLINE},
@ -2819,6 +2821,41 @@ static void sremCommand(redisClient *c) {
}
}
static void smoveCommand(redisClient *c) {
robj *srcset, *dstset;
srcset = lookupKeyWrite(c->db,c->argv[1]);
dstset = lookupKeyWrite(c->db,c->argv[2]);
/* If the source key does not exist return 0, if it's of the wrong type
* raise an error */
if (srcset == NULL || srcset->type != REDIS_SET) {
addReply(c, srcset ? shared.wrongtypeerr : shared.czero);
return;
}
/* Error if the destination key is not a set as well */
if (dstset && dstset->type != REDIS_SET) {
addReply(c,shared.wrongtypeerr);
return;
}
/* Remove the element from the source set */
if (dictDelete(srcset->ptr,c->argv[3]) == DICT_ERR) {
/* Key not found in the src set! return zero */
addReply(c,shared.czero);
return;
}
server.dirty++;
/* Add the element to the destination set */
if (!dstset) {
dstset = createSetObject();
dictAdd(c->db->dict,c->argv[2],dstset);
incrRefCount(c->argv[2]);
}
if (dictAdd(dstset->ptr,c->argv[3],NULL) == DICT_OK)
incrRefCount(c->argv[3]);
addReply(c,shared.cone);
}
static void sismemberCommand(redisClient *c) {
robj *set;