Pārlūkot izejas kodu

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

Daniele Alessandri 14 gadi atpakaļ
vecāks
revīzija
d6a445f1ec

+ 4 - 1
lib/Predis/Commands/SetIntersectionStore.php

@@ -7,6 +7,9 @@ use Predis\Utils;
 class SetIntersectionStore extends Command {
     public function getId() { return 'SINTERSTORE'; }
     public function filterArguments(Array $arguments) {
-        return Utils::filterArrayArguments($arguments);
+        if (count($arguments) === 2 && is_array($arguments[1])) {
+            return array_merge(array($arguments[0]), $arguments[1]);
+        }
+        return $arguments;
     }
 }

+ 6 - 0
test/RedisCommandsTest.php

@@ -1013,6 +1013,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) {
@@ -1076,6 +1079,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) {