|
@@ -0,0 +1,136 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/*
|
|
|
+ * This file is part of the Predis package.
|
|
|
+ *
|
|
|
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
|
+ *
|
|
|
+ * For the full copyright and license information, please view the LICENSE
|
|
|
+ * file that was distributed with this source code.
|
|
|
+ */
|
|
|
+
|
|
|
+namespace Predis\Command;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @group commands
|
|
|
+ * @group realm-zset
|
|
|
+ */
|
|
|
+class ZSetLexCountTest extends PredisCommandTestCase
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ protected function getExpectedCommand()
|
|
|
+ {
|
|
|
+ return 'Predis\Command\ZSetLexCount';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ protected function getExpectedId()
|
|
|
+ {
|
|
|
+ return 'ZLEXCOUNT';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testFilterArguments()
|
|
|
+ {
|
|
|
+ $arguments = array('key', '+', '-');
|
|
|
+ $expected = array('key', '+', '-');
|
|
|
+
|
|
|
+ $command = $this->getCommand();
|
|
|
+ $command->setArguments($arguments);
|
|
|
+
|
|
|
+ $this->assertSame($expected, $command->getArguments());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testParseResponse()
|
|
|
+ {
|
|
|
+ $this->assertSame(1, $this->getCommand()->parseResponse(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group connected
|
|
|
+ */
|
|
|
+ public function testExclusiveIntervalRange()
|
|
|
+ {
|
|
|
+ $this->markTestSkippedOnRedisVersionBelow('2.8.9', 'Lexicographical operations on sorted sets require Redis >= 2.8.9.', true);
|
|
|
+
|
|
|
+ $redis = $this->getClient();
|
|
|
+
|
|
|
+ $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
|
|
|
+
|
|
|
+ $this->assertSame(3, $redis->zlexcount('letters', '(b', '(f'));
|
|
|
+ $this->assertSame(5, $redis->zlexcount('letters', '(b', '(z'));
|
|
|
+ $this->assertSame(4, $redis->zlexcount('letters', '(0', '(e'));
|
|
|
+ $this->assertSame(0, $redis->zlexcount('letters', '(f', '(b'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group connected
|
|
|
+ */
|
|
|
+ public function testInclusiveIntervalRange()
|
|
|
+ {
|
|
|
+ $this->markTestSkippedOnRedisVersionBelow('2.8.9', 'Lexicographical operations on sorted sets require Redis >= 2.8.9.', true);
|
|
|
+
|
|
|
+ $redis = $this->getClient();
|
|
|
+
|
|
|
+ $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
|
|
|
+
|
|
|
+ $this->assertSame(5, $redis->zlexcount('letters', '[b', '[f'));
|
|
|
+ $this->assertSame(6, $redis->zlexcount('letters', '[b', '[z'));
|
|
|
+ $this->assertSame(5, $redis->zlexcount('letters', '[0', '[e'));
|
|
|
+ $this->assertSame(0, $redis->zlexcount('letters', '[f', '[b'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group connected
|
|
|
+ */
|
|
|
+ public function testWholeRangeInterval()
|
|
|
+ {
|
|
|
+ $this->markTestSkippedOnRedisVersionBelow('2.8.9', 'Lexicographical operations on sorted sets require Redis >= 2.8.9.', true);
|
|
|
+
|
|
|
+ $redis = $this->getClient();
|
|
|
+
|
|
|
+ $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
|
|
|
+
|
|
|
+ $this->assertSame(7, $redis->zlexcount('letters', '-', '+'));
|
|
|
+ $this->assertSame(0, $redis->zlexcount('letters', '+', '-'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group connected
|
|
|
+ * @expectedException Predis\Response\ServerException
|
|
|
+ * @expectedExceptionMessage min or max not valid string range item
|
|
|
+ */
|
|
|
+ public function testThrowsExceptionOnInvalidRangeFormat()
|
|
|
+ {
|
|
|
+ $this->markTestSkippedOnRedisVersionBelow('2.8.9', 'Lexicographical operations on sorted sets require Redis >= 2.8.9.', true);
|
|
|
+
|
|
|
+ $redis = $this->getClient();
|
|
|
+
|
|
|
+ $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
|
|
|
+ $redis->zlexcount('letters', 'b', 'f');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group connected
|
|
|
+ * @expectedException Predis\Response\ServerException
|
|
|
+ * @expectedExceptionMessage Operation against a key holding the wrong kind of value
|
|
|
+ */
|
|
|
+ public function testThrowsExceptionOnWrongType()
|
|
|
+ {
|
|
|
+ $this->markTestSkippedOnRedisVersionBelow('2.8.9', 'Lexicographical operations on sorted sets require Redis >= 2.8.9.', true);
|
|
|
+
|
|
|
+ $redis = $this->getClient();
|
|
|
+
|
|
|
+ $redis->set('foo', 'bar');
|
|
|
+ $redis->zlexcount('foo', '+', '-');
|
|
|
+ }
|
|
|
+}
|