From 1e47fb88f383bf88f48ba97778a2702837a9e465 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 27 Mar 2011 10:25:27 +0200 Subject: [PATCH] Fix SINTERSTORE and SUNIONSTORE to accept an array for the list of source keys. --- CHANGELOG | 4 +++- lib/Predis.php | 12 ++++++++++++ test/RedisCommandsTest.php | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a01ce815..a143d61f 100644 --- a/CHANGELOG +++ b/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. diff --git a/lib/Predis.php b/lib/Predis.php index 35c1d512..864f985e 100644 --- a/lib/Predis.php +++ b/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 { diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index c547efb2..5a0c62a7 100644 --- a/test/RedisCommandsTest.php +++ b/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) {