Fix SINTERSTORE and SUNIONSTORE to accept an array for the list of source keys.

This commit is contained in:
Daniele Alessandri
2011-03-27 10:25:27 +02:00
parent b882344840
commit 1e47fb88f3
3 changed files with 21 additions and 1 deletions
+3 -1
View File
@@ -16,7 +16,9 @@ v0.6.6 (2011-xx-xx)
* ZUNIONSTORE and ZINTERSTORE can accept an array to specify a list of the
source keys to be used to populate the destination key.
* MGET, SINTER and SUNION can accept an array to specify the list of keys.
* MGET, SINTER and SUNION can accept an array to specify the list of keys.
SINTERSTORE and SUNIONSTORE can also accept an array to specify the list
of source keys.
* SUBSCRIBE and PSUBSCRIBE can accept a list of channels for subscription.
+12
View File
@@ -2687,6 +2687,12 @@ class SetIntersection extends \Predis\MultiBulkCommand {
class SetIntersectionStore extends \Predis\MultiBulkCommand {
public function getCommandId() { return 'SINTERSTORE'; }
public function filterArguments(Array $arguments) {
if (count($arguments) === 2 && is_array($arguments[1])) {
return array_merge(array($arguments[0]), $arguments[1]);
}
return $arguments;
}
}
class SetUnion extends SetIntersection {
@@ -2695,6 +2701,12 @@ class SetUnion extends SetIntersection {
class SetUnionStore extends \Predis\MultiBulkCommand {
public function getCommandId() { return 'SUNIONSTORE'; }
public function filterArguments(Array $arguments) {
if (count($arguments) === 2 && is_array($arguments[1])) {
return array_merge(array($arguments[0]), $arguments[1]);
}
return $arguments;
}
}
class SetDifference extends \Predis\MultiBulkCommand {
+6
View File
@@ -1012,6 +1012,9 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->set('foo', 'bar');
$this->assertEquals(count($setA), $this->redis->sinterstore('foo', 'setA'));
// accepts an array for the list of source keys
$this->assertEquals(4, $this->redis->sinterstore('setC', array('setA', 'setB')));
// wrong type
$this->redis->set('foo', 'bar');
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
@@ -1075,6 +1078,9 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->set('foo', 'bar');
$this->assertEquals(count($setA), $this->redis->sunionstore('foo', 'setA'));
// accepts an array for the list of source keys
$this->assertEquals(9, $this->redis->sunionstore('setC', array('setA', 'setB')));
// wrong type
$this->redis->set('foo', 'bar');
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {