فهرست منبع

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

Daniele Alessandri 14 سال پیش
والد
کامیت
1e47fb88f3
3فایلهای تغییر یافته به همراه21 افزوده شده و 1 حذف شده
  1. 3 1
      CHANGELOG
  2. 12 0
      lib/Predis.php
  3. 6 0
      test/RedisCommandsTest.php

+ 3 - 1
CHANGELOG

@@ -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 - 0
lib/Predis.php

@@ -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 - 0
test/RedisCommandsTest.php

@@ -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) {