diff --git a/lib/Predis/Commands/ZSetUnionStore.php b/lib/Predis/Commands/ZSetUnionStore.php index 442b184f..790b79e1 100644 --- a/lib/Predis/Commands/ZSetUnionStore.php +++ b/lib/Predis/Commands/ZSetUnionStore.php @@ -6,12 +6,17 @@ class ZSetUnionStore extends Command { public function getId() { return 'ZUNIONSTORE'; } public function filterArguments(Array $arguments) { $options = array(); - $argc = count($arguments); - if ($argc > 1 && is_array($arguments[$argc - 1])) { + $argc = count($arguments); + if ($argc > 2 && is_array($arguments[$argc - 1])) { $options = $this->prepareOptions(array_pop($arguments)); } - $args = is_array($arguments[0]) ? $arguments[0] : $arguments; - return array_merge($args, $options); + if (is_array($arguments[1])) { + $arguments = array_merge( + array($arguments[0], count($arguments[1])), + $arguments[1] + ); + } + return array_merge($arguments, $options); } private function prepareOptions($options) { $opts = array_change_key_case($options, CASE_UPPER); diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index 500610cc..e29863fa 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -1504,6 +1504,23 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { $this->redis->zrange('zsetc', 0, -1, 'withscores') ); + // using an array to pass the list of source keys + $sourceKeys = array('zseta', 'zsetb'); + + $this->assertEquals(4, $this->redis->zunionstore('zsetc', $sourceKeys)); + $this->assertEquals( + array(array('a', 1), array('b', 3), array('d', 3), array('c', 5)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + // using an array to pass the list of source keys + options array + $options = array('weights' => array(2, 3)); + $this->assertEquals(4, $this->redis->zunionstore('zsetc', $sourceKeys, $options)); + $this->assertEquals( + array(array('a', 2), array('b', 7), array('d', 9), array('c', 12)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) { $test->redis->set('zsetFake', 'fake'); $test->redis->zunionstore('zsetc', 2, 'zseta', 'zsetFake'); @@ -1549,6 +1566,23 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { $this->redis->zrange('zsetc', 0, -1, 'withscores') ); + // using an array to pass the list of source keys + $sourceKeys = array('zseta', 'zsetb'); + + $this->assertEquals(2, $this->redis->zinterstore('zsetc', $sourceKeys)); + $this->assertEquals( + array(array('b', 3), array('c', 5)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + // using an array to pass the list of source keys + options array + $options = array('weights' => array(2, 3)); + $this->assertEquals(2, $this->redis->zinterstore('zsetc', $sourceKeys, $options)); + $this->assertEquals( + array(array('b', 7), array('c', 12)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) { $test->redis->set('zsetFake', 'fake'); $test->redis->zinterstore('zsetc', 2, 'zseta', 'zsetFake');