Merge remote-tracking branch 'github/pr/235' into v1.0

Conflicts:
	.travis.yml
	CHANGELOG.md
	VERSION
	package.ini
	src/Client.php
This commit is contained in:
Daniele Alessandri
2015-07-07 14:52:09 +02:00
17 changed files with 254 additions and 21 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
[![Latest Stable Version](https://poser.pugx.org/predis/predis/v/stable.png)](https://packagist.org/packages/predis/predis)
[![Total Downloads](https://poser.pugx.org/predis/predis/downloads.png)](https://packagist.org/packages/predis/predis)
[![License](https://poser.pugx.org/predis/predis/license.svg)](https://packagist.org/packages/predis/predis)
[![Build Status](https://travis-ci.org/nrk/predis.svg?branch=v1.0)](https://travis-ci.org/nrk/predis)
[![Build Status](https://travis-ci.org/nrk/predis.svg?branch=master)](https://travis-ci.org/nrk/predis)
[![HHVM Status](http://hhvm.h4cc.de/badge/predis/predis.png)](http://hhvm.h4cc.de/package/predis/predis)
Predis is a flexible and feature-complete [Redis](http://redis.io) client library for PHP >= 5.3.
+6 -1
View File
@@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=5.3.2"
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
@@ -27,5 +27,10 @@
},
"autoload": {
"psr-4": {"Predis\\": "src/"}
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ channel = "pear.nrk.io"
author = "Daniele Alessandri \"nrk\" <suppakilla@gmail.com>"
[require]
php = ">= 5.3.2"
php = ">= 5.3.9"
pearinstaller = "1.4.1"
[roles]
+1
View File
@@ -138,6 +138,7 @@ abstract class ClusterStrategy implements StrategyInterface
'ZLEXCOUNT' => $getKeyFromFirstArgument,
'ZRANGEBYLEX' => $getKeyFromFirstArgument,
'ZREMRANGEBYLEX' => $getKeyFromFirstArgument,
'ZREVRANGEBYLEX' => $getKeyFromFirstArgument,
/* commands operating on hashes */
'HDEL' => $getKeyFromFirstArgument,
@@ -155,6 +155,7 @@ class KeyPrefixProcessor implements ProcessorInterface
'ZLEXCOUNT' => 'self::first',
'ZRANGEBYLEX' => 'self::first',
'ZREMRANGEBYLEX' => 'self::first',
'ZREVRANGEBYLEX' => 'self::first',
);
}
+21
View File
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Predis package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command;
class ZSetReverseRangeByLex extends ZSetRangeByLex
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'ZREVRANGEBYLEX';
}
}
+1
View File
@@ -246,6 +246,7 @@ class RedisVersion280 extends RedisProfile
'ZLEXCOUNT' => 'Predis\Command\ZSetLexCount',
'ZRANGEBYLEX' => 'Predis\Command\ZSetRangeByLex',
'ZREMRANGEBYLEX' => 'Predis\Command\ZSetRemoveRangeByLex',
'ZREVRANGEBYLEX' => 'Predis\Command\ZSetReverseRangeByLex',
/* commands operating on hashes */
'HSCAN' => 'Predis\Command\HashScan',
+1
View File
@@ -246,6 +246,7 @@ class RedisVersion300 extends RedisProfile
'ZLEXCOUNT' => 'Predis\Command\ZSetLexCount',
'ZRANGEBYLEX' => 'Predis\Command\ZSetRangeByLex',
'ZREMRANGEBYLEX' => 'Predis\Command\ZSetRemoveRangeByLex',
'ZREVRANGEBYLEX' => 'Predis\Command\ZSetReverseRangeByLex',
/* commands operating on hashes */
'HSCAN' => 'Predis\Command\HashScan',
+1
View File
@@ -211,6 +211,7 @@ class ReplicationStrategy
'ZSCAN' => true,
'ZLEXCOUNT' => true,
'ZRANGEBYLEX' => true,
'ZREVRANGEBYLEX' => true,
'HGET' => true,
'HMGET' => true,
'HEXISTS' => true,
@@ -349,6 +349,7 @@ class PredisStrategyTest extends PredisTestCase
'ZLEXCOUNT' => 'keys-first',
'ZRANGEBYLEX' => 'keys-first',
'ZREMRANGEBYLEX' => 'keys-first',
'ZREVRANGEBYLEX' => 'keys-first',
/* commands operating on hashes */
'HDEL' => 'keys-first',
@@ -359,6 +359,7 @@ class RedisStrategyTest extends PredisTestCase
'ZLEXCOUNT' => 'keys-first',
'ZRANGEBYLEX' => 'keys-first',
'ZREMRANGEBYLEX' => 'keys-first',
'ZREVRANGEBYLEX' => 'keys-first',
/* commands operating on hashes */
'HDEL' => 'keys-first',
@@ -825,6 +825,10 @@ class KeyPrefixProcessorTest extends PredisTestCase
array('key', '-', '+'),
array('prefix:key', '-', '+'),
),
array('ZREVRANGEBYLEX',
array('key', '+', '-', 'LIMIT', '0', '10'),
array('prefix:key', '+', '-', 'LIMIT', '0', '10'),
),
);
}
}
@@ -0,0 +1,192 @@
<?php
/*
* This file is part of the Predis package.
*
* 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 ZSetRevRangeByLexTest extends PredisCommandTestCase
{
/**
* {@inheritdoc}
*/
protected function getExpectedCommand()
{
return 'Predis\Command\ZSetReverseRangeByLex';
}
/**
* {@inheritdoc}
*/
protected function getExpectedId()
{
return 'ZREVRANGEBYLEX';
}
/**
* @group disconnected
*/
public function testFilterArguments()
{
$modifiers = array(
'limit' => array(0, 100),
);
$arguments = array('zset', '[a', '[z', $modifiers);
$expected = array('zset', '[a', '[z', 'LIMIT', 0, 100);
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testFilterArgumentsWithNamedLimit()
{
$arguments = array('zset', '[a', '[z', array('limit' => array('offset' => 1, 'count' => 2)));
$expected = array('zset', '[a', '[z', 'LIMIT', 1, 2);
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponse()
{
$raw = array('a', 'b', 'c');
$expected = array('a', 'b', 'c');
$command = $this->getCommand();
$this->assertSame($expected, $command->parseResponse($raw));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
*/
public function testReturnsElementsInWholeRange()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$this->assertSame(array('g', 'f', 'e', 'd', 'c', 'b', 'a'), $redis->zrevrangebylex('letters', '+', '-'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '-', '+'));
$this->assertSame(array(), $redis->zrevrangebylex('unknown', '-', '+'));
$this->assertSame(array(), $redis->zrevrangebylex('unknown', '+', '-'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
*/
public function testReturnsElementsInInclusiveRange()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$this->assertSame(array('a'), $redis->zrevrangebylex('letters', '[a', '[a'));
$this->assertSame(array('f', 'e', 'd', 'c'), $redis->zrevrangebylex('letters', '[f', '[c'));
$this->assertSame(array('g', 'f', 'e'), $redis->zrevrangebylex('letters', '+', '[e'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '-', '[c'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '[z', '[x'));
$this->assertSame(array(), $redis->zrevrangebylex('unknown', '[1', '[0'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
*/
public function testReturnsElementsInExclusiveRange()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$this->assertSame(array(), $redis->zrevrangebylex('letters', '(a', '(a'));
$this->assertSame(array('e', 'd'), $redis->zrevrangebylex('letters', '(f', '(c'));
$this->assertSame(array('g', 'f'), $redis->zrevrangebylex('letters', '+', '(e'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '-', '(c'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '(z', '(x'));
$this->assertSame(array(), $redis->zrevrangebylex('unknown', '(1', '(0'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
*/
public function testReturnsElementsInMixedRange()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$this->assertSame(array(), $redis->zrevrangebylex('letters', '[a', '(a'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '(a', '[a'));
$this->assertSame(array('f', 'e', 'd'), $redis->zrevrangebylex('letters', '[f', '(c'));
$this->assertSame(array('e', 'd', 'c'), $redis->zrevrangebylex('letters', '(f', '[c'));
$this->assertSame(array(), $redis->zrevrangebylex('unknown', '[5', '(0'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
*/
public function testRangeWithLimitModifier()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$this->assertSame(array('e', 'd', 'c'), $redis->zrevrangebylex('letters', '+', '-', 'LIMIT', '2', '3'));
$this->assertSame(array('e', 'd', 'c'), $redis->zrevrangebylex('letters', '+', '-', array('limit' => array(2, 3))));
$this->assertSame(array('e', 'd', 'c'), $redis->zrevrangebylex('letters', '+', '-', array('limit' => array('offset' => 2, 'count' => 3))));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '[f', '[a', 'LIMIT', '2', '0'));
$this->assertSame(array(), $redis->zrevrangebylex('letters', '[f', '[a', 'LIMIT', '-4', '2'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessage min or max not valid string range item
*/
public function testThrowsExceptionOnInvalidRangeFormat()
{
$redis = $this->getClient();
$redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g');
$redis->zrevrangebylex('letters', 'f', 'b');
}
/**
* @group connected
* @requiresRedisVersion >= 2.8.9
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessage Operation against a key holding the wrong kind of value
*/
public function testThrowsExceptionOnWrongType()
{
$redis = $this->getClient();
$redis->set('foo', 'bar');
$redis->zrevrangebylex('foo', '+', '-');
}
}
+7 -6
View File
@@ -181,12 +181,13 @@ class RedisUnstableTest extends PredisProfileTestCase
140 => 'ZLEXCOUNT',
141 => 'ZRANGEBYLEX',
142 => 'ZREMRANGEBYLEX',
143 => 'HSCAN',
144 => 'PUBSUB',
145 => 'PFADD',
146 => 'PFCOUNT',
147 => 'PFMERGE',
148 => 'COMMAND',
143 => 'ZREVRANGEBYLEX',
144 => 'HSCAN',
145 => 'PUBSUB',
146 => 'PFADD',
147 => 'PFCOUNT',
148 => 'PFMERGE',
149 => 'COMMAND',
);
}
}
+7 -6
View File
@@ -181,12 +181,13 @@ class RedisVersion280Test extends PredisProfileTestCase
140 => 'ZLEXCOUNT',
141 => 'ZRANGEBYLEX',
142 => 'ZREMRANGEBYLEX',
143 => 'HSCAN',
144 => 'PUBSUB',
145 => 'PFADD',
146 => 'PFCOUNT',
147 => 'PFMERGE',
148 => 'COMMAND',
143 => 'ZREVRANGEBYLEX',
144 => 'HSCAN',
145 => 'PUBSUB',
146 => 'PFADD',
147 => 'PFCOUNT',
148 => 'PFMERGE',
149 => 'COMMAND',
);
}
}
+7 -6
View File
@@ -181,12 +181,13 @@ class RedisVersion300Test extends PredisProfileTestCase
140 => 'ZLEXCOUNT',
141 => 'ZRANGEBYLEX',
142 => 'ZREMRANGEBYLEX',
143 => 'HSCAN',
144 => 'PUBSUB',
145 => 'PFADD',
146 => 'PFCOUNT',
147 => 'PFMERGE',
148 => 'COMMAND',
143 => 'ZREVRANGEBYLEX',
144 => 'HSCAN',
145 => 'PUBSUB',
146 => 'PFADD',
147 => 'PFCOUNT',
148 => 'PFMERGE',
149 => 'COMMAND',
);
}
}
@@ -346,6 +346,7 @@ class ReplicationStrategyTest extends PredisTestCase
'ZLEXCOUNT' => 'read',
'ZRANGEBYLEX' => 'read',
'ZREMRANGEBYLEX' => 'write',
'ZREVRANGEBYLEX' => 'read',
/* commands operating on hashes */
'HDEL' => 'write',