Merge branch 'cmd_zincrby'

This commit is contained in:
Daniele Alessandri
2009-12-19 10:49:34 +01:00
2 changed files with 26 additions and 0 deletions
+6
View File
@@ -274,6 +274,8 @@ class Client {
/* commands operating on sorted sets */
'zadd' => '\Predis\Commands\ZSetAdd',
'zsetAdd' => '\Predis\Commands\ZSetAdd',
'zincrby' => '\Predis\Commands\ZSetIncrementBy',
'zsetIncrementBy' => '\Predis\Commands\ZSetIncrementBy',
'zrem' => '\Predis\Commands\ZSetRemove',
'zsetRemove' => '\Predis\Commands\ZSetRemove',
'zrange' => '\Predis\Commands\ZSetRange',
@@ -1139,6 +1141,10 @@ class ZSetAdd extends \Predis\BulkCommand {
public function parseResponse($data) { return (bool) $data; }
}
class ZSetIncrementBy extends \Predis\BulkCommand {
public function getCommandId() { return 'ZINCRBY'; }
}
class ZSetRemove extends \Predis\BulkCommand {
public function getCommandId() { return 'ZREM'; }
public function parseResponse($data) { return (bool) $data; }
+20
View File
@@ -866,6 +866,26 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
});
}
function testZsetIncrementBy() {
$this->assertEquals(1, $this->redis->zsetIncrementBy('zsetDoesNotExist', 1, 'foo'));
$this->assertEquals('zset', $this->redis->type('zsetDoesNotExist'));
RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());
$this->assertEquals(-5, $this->redis->zsetIncrementBy('zset', 5, 'a'));
$this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'b'));
$this->assertEquals(10, $this->redis->zsetIncrementBy('zset', 0, 'c'));
$this->assertEquals(0, $this->redis->zsetIncrementBy('zset', -20, 'd'));
$this->assertEquals(2, $this->redis->zsetIncrementBy('zset', 2, 'd'));
$this->assertEquals(-10, $this->redis->zsetIncrementBy('zset', -30, 'e'));
$this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'x'));
// wrong type
$this->redis->set('foo', 'bar');
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->zsetIncrementBy('foo', 1, 'a');
});
}
function testZsetRemove() {
RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());