diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index af790ae1..0d863fac 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -1188,6 +1188,58 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { }); } + function testZsetUnion() { + $zsetA = RC::zsetAddAndReturn($this->redis, 'zseta', array('a' => 1, 'b' => 2, 'c' => 3)); + $zsetB = RC::zsetAddAndReturn($this->redis, 'zsetb', array('b' => 1, 'c' => 2, 'd' => 3)); + + // basic ZUNION + $this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb')); + $this->assertEquals( + array(array('a', 1), array('b', 3), array('d', 3), array('c', 5)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + $this->assertEquals(3, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetbNull')); + $this->assertEquals( + array(array('a', 1), array('b', 2), array('c', 3)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + $this->assertEquals(3, $this->redis->zunion('zsetc', 2, 'zsetaNull', 'zsetb')); + $this->assertEquals( + array(array('b', 1), array('c', 2), array('d', 3)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + $this->assertEquals(0, $this->redis->zunion('zsetc', 2, 'zsetaNull', 'zsetbNull')); + + // with WEIGHTS + $this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'WEIGHTS', 2, 3)); + $this->assertEquals( + array(array('a', 2), array('b', 7), array('d', 9), array('c', 12)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + // with AGGREGATE (min) + $this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'AGGREGATE', 'MIN')); + $this->assertEquals( + array(array('a', 1), array('b', 1), array('c', 2), array('d', 3)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + // with AGGREGATE (max) + $this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'AGGREGATE', 'MAX')); + $this->assertEquals( + array(array('a', 1), array('b', 2), array('c', 3), array('d', 3)), + $this->redis->zrange('zsetc', 0, -1, 'withscores') + ); + + RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) { + $test->redis->set('zsetFake', 'fake'); + $test->redis->zunion('zsetc', 2, 'zseta', 'zsetFake'); + }); + } + function testZsetCount() { $zset = RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());