Compare commits

...

11 Commits

Author SHA1 Message Date
Daniele Alessandri bd961a767b Update CHANGELOG. It's release time! 2010-07-11 17:12:28 +02:00
Daniele Alessandri b3599a8e6b Update CHANGELOG. 2010-07-11 17:11:58 +02:00
Daniele Alessandri 0b46de424e Test suite: add a test for the LIMIT modifier of ZRANGEBYSCORE configured via associative array. 2010-07-11 17:02:33 +02:00
Daniele Alessandri 73bdfc2d72 Fix handling of the WEIGHT modifier for ZUNIONSTORE and ZINTERSTORE with more than two weights specified. 2010-07-11 16:35:03 +02:00
Daniele Alessandri 3077e76708 Update CHANGELOG. 2010-07-11 16:24:06 +02:00
Daniele Alessandri 208fdf6daf Update CHANGELOG. 2010-07-11 15:32:14 +02:00
Daniele Alessandri 7d7995ff8f Update CHANGELOG. 2010-07-07 20:07:15 +02:00
Daniele Alessandri 418197af75 Add tests for the new options handling for the ZRANGE commands family. 2010-07-07 19:59:16 +02:00
Daniele Alessandri 90cb9d437d Add support for the LIMIT modifier in ZRANGEBYSCORE. 2010-07-07 19:58:52 +02:00
Daniele Alessandri 4668bdca83 ZRANGE, ZREVRANGE and ZRANGEBYSCORE accepts an array instance for optional modifiers. 2010-07-07 19:58:41 +02:00
Daniele Alessandri 93a3c184ed Bump version number. 2010-07-02 22:31:39 +02:00
4 changed files with 106 additions and 26 deletions
+23 -12
View File
@@ -1,13 +1,21 @@
v0.6.1 (2010-xx-xx)
v0.6.1 (2010-07-11)
* Minor internal improvements and clean ups.
* New commands available in the Redis v2.2 profile (dev):
- Misc. : WATCH, UNWATCH
* Minor internal improvements and clean ups.
* Optional modifiers for ZRANGE, ZREVRANGE and ZRANGEBYSCORE queries are
supported using an associative array passed as the last argument of their
respective methods.
* The constructor of Predis\Client::__construct now accepts also instances
of Predis\ConnectionParameters.
* The LIMIT modifier for ZRANGEBYSCORE can be specified using either:
- an indexed array: array($offset, $count)
- an associative array: array('offset' => $offset, 'count' => $count)
* Predis\MultiExecBlock and Predis\PubSubContext will throw an exception
* The method Predis\Client::__construct() now accepts also instances of
Predis\ConnectionParameters.
* Predis\MultiExecBlock and Predis\PubSubContext now throw an exception
when trying to create their instances using a profile that does not
support the required Redis commands or when the client is connected to
a cluster of connections.
@@ -17,14 +25,17 @@ v0.6.1 (2010-xx-xx)
- support for WATCH and UNWATCH when using the current development
profile (Redis v2.2) and aborted transactions.
* New method signature for Predis\Client::multiExec(). Now it is able to
accept an array of options for the underlying Predis\MultiExecBlock, but
it is still backwards compatible with previous releases of Predis.
* New signature for Predis\Client::multiExec() which is now able to accept
an array of options for the underlying instance of Predis\MultiExecBlock.
Backwards compatibility with previous releases of Predis is ensured.
* New method signature for Predis\Client::pipeline(). Now it is able to
accept an array of options for the underlying Predis\CommandPipeline,
but it is still backwards compatible with previous releases of Predis.
Predis\Client::pipelineSafe() is to be considered obsolete.
* New signature for Predis\Client::pipeline() which is now able to accept
an array of options for the underlying instance of Predis\CommandPipeline.
Backwards compatibility with previous releases of Predis is ensured.
The method Predis\Client::pipelineSafe() is to be considered deprecated.
* FIX: The WEIGHT modifier for ZUNIONSTORE and ZINTERSTORE was handled
incorrectly with more than two weights specified.
v0.6.0 (2010-05-24)
* Switched to the new multi-bulk request protocol for all of the commands
+1 -1
View File
@@ -1 +1 @@
0.6.0
0.6.1
+47 -13
View File
@@ -2550,8 +2550,9 @@ class ZSetUnionStore extends \Predis\MultiBulkCommand {
$finalizedOpts = array();
if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) {
$finalizedOpts[] = 'WEIGHTS';
$finalizedOpts[] = $opts['WEIGHTS'][0];
$finalizedOpts[] = $opts['WEIGHTS'][1];
foreach ($opts['WEIGHTS'] as $weight) {
$finalizedOpts[] = $weight;
}
}
if (isset($opts['AGGREGATE'])) {
$finalizedOpts[] = 'AGGREGATE';
@@ -2566,20 +2567,42 @@ class ZSetIntersectionStore extends \Predis\Commands\ZSetUnionStore {
}
class ZSetRange extends \Predis\MultiBulkCommand {
private $_withScores = false;
public function getCommandId() { return 'ZRANGE'; }
public function parseResponse($data) {
$arguments = $this->getArguments();
public function filterArguments(Array $arguments) {
if (count($arguments) === 4) {
if (strtolower($arguments[3]) === 'withscores') {
if ($data instanceof \Iterator) {
return new \Predis\Shared\MultiBulkResponseKVIterator($data);
}
$result = array();
for ($i = 0; $i < count($data); $i++) {
$result[] = array($data[$i], $data[++$i]);
}
return $result;
$lastType = gettype($arguments[3]);
if ($lastType === 'string' && strtolower($arguments[3]) === 'withscores') {
// used for compatibility with older versions
$arguments[3] = array('WITHSCORES' => true);
$lastType = 'array';
}
if ($lastType === 'array') {
$options = $this->prepareOptions(array_pop($arguments));
return array_merge($arguments, $options);
}
}
return $arguments;
}
protected function prepareOptions($options) {
$opts = array_change_key_case($options, CASE_UPPER);
$finalizedOpts = array();
if (isset($opts['WITHSCORES'])) {
$finalizedOpts[] = 'WITHSCORES';
$this->_withScores = true;
}
return $finalizedOpts;
}
public function parseResponse($data) {
if ($this->_withScores) {
if ($data instanceof \Iterator) {
return new \Predis\Shared\MultiBulkResponseKVIterator($data);
}
$result = array();
for ($i = 0; $i < count($data); $i++) {
$result[] = array($data[$i], $data[++$i]);
}
return $result;
}
return $data;
}
@@ -2591,6 +2614,17 @@ class ZSetReverseRange extends \Predis\Commands\ZSetRange {
class ZSetRangeByScore extends \Predis\Commands\ZSetRange {
public function getCommandId() { return 'ZRANGEBYSCORE'; }
protected function prepareOptions($options) {
$opts = array_change_key_case($options, CASE_UPPER);
$finalizedOpts = array();
if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) {
$limit = array_change_key_case($opts['LIMIT'], CASE_UPPER);
$finalizedOpts[] = 'LIMIT';
$finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0];
$finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1];
}
return array_merge($finalizedOpts, parent::prepareOptions($options));
}
}
class ZSetCount extends \Predis\MultiBulkCommand {
+35
View File
@@ -1095,6 +1095,11 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->zrange('zset', 0, 2, 'withscores')
);
$this->assertEquals(
array(array('a', -10), array('b', 0), array('c', 10)),
$this->redis->zrange('zset', 0, 2, array('withscores' => true))
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('foo', 'bar');
$test->redis->zrange('foo', 0, -1);
@@ -1149,6 +1154,11 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->zrevrange('zset', 0, 2, 'withscores')
);
$this->assertEquals(
array(array('f', 30), array('e', 20), array('d', 20)),
$this->redis->zrevrange('zset', 0, 2, array('withscores' => true))
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('foo', 'bar');
$test->redis->zrevrange('foo', 0, -1);
@@ -1183,6 +1193,31 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->zrangebyscore('zset', 10, 20, 'withscores')
);
$this->assertEquals(
array(array('c', 10), array('d', 20), array('e', 20)),
$this->redis->zrangebyscore('zset', 10, 20, array('withscores' => true))
);
$this->assertEquals(
array('d', 'e'),
$this->redis->zrangebyscore('zset', 10, 20, array('limit' => array(1, 2)))
);
$this->assertEquals(
array('d', 'e'),
$this->redis->zrangebyscore('zset', 10, 20, array(
'limit' => array('offset' => 1, 'count' => 2)
))
);
$this->assertEquals(
array(array('d', 20), array('e', 20)),
$this->redis->zrangebyscore('zset', 10, 20, array(
'limit' => array(1, 2),
'withscores' => true,
))
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('foo', 'bar');
$test->redis->zrangebyscore('foo', 0, 0);