New command: SETBIT (Redis v2.2-dev).

Conflicts:

	lib/Predis.php
This commit is contained in:
Daniele Alessandri
2010-12-18 17:36:48 +01:00
parent e1924551b1
commit 0b9bca8ce1
3 changed files with 39 additions and 0 deletions
+5
View File
@@ -1797,6 +1797,7 @@ class RedisServer_vNext extends RedisServer_v2_0 {
'strlen' => '\Predis\Commands\Strlen',
'setrange' => '\Predis\Commands\SetRange',
'getrange' => '\Predis\Commands\GetRange',
'setbit' => '\Predis\Commands\SetBit',
/* commands operating on the key space */
'persist' => '\Predis\Commands\Persist',
@@ -2360,6 +2361,10 @@ class Substr extends Command {
public function getCommandId() { return 'SUBSTR'; }
}
class SetBit extends Command {
public function getCommandId() { return 'SETBIT'; }
}
class Strlen extends Command {
public function getCommandId() { return 'STRLEN'; }
}
+2
View File
@@ -36,6 +36,8 @@ class RC {
const EXCEPTION_EXEC_NO_MULTI = 'EXEC without MULTI';
const EXCEPTION_SETEX_TTL = 'invalid expire time in SETEX';
const EXCEPTION_HASH_VALNOTINT = 'hash value is not an integer';
const EXCEPTION_BIT_VALUE = 'bit is not an integer or out of range';
const EXCEPTION_BIT_OFFSET = 'bit offset is not an integer or out of range';
private static $_connection;
+32
View File
@@ -259,6 +259,38 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
});
}
function testSetBit() {
$this->assertEquals(0, $this->redis->setbit('binary', 31, 1));
$this->assertEquals(0, $this->redis->setbit('binary', 0, 1));
$this->assertEquals(4, $this->redis->strlen('binary'));
$this->assertEquals("\x80\x00\00\x01", $this->redis->get('binary'));
$this->assertEquals(1, $this->redis->setbit('binary', 0, 0));
$this->assertEquals(0, $this->redis->setbit('binary', 0, 0));
$this->assertEquals("\x00\x00\00\x01", $this->redis->get('binary'));
RC::testForServerException($this, RC::EXCEPTION_BIT_OFFSET, function($test) {
$test->redis->setbit('binary', -1, 1);
});
RC::testForServerException($this, RC::EXCEPTION_BIT_OFFSET, function($test) {
$test->redis->setbit('binary', 'invalid', 1);
});
RC::testForServerException($this, RC::EXCEPTION_BIT_VALUE, function($test) {
$test->redis->setbit('binary', 15, 255);
});
RC::testForServerException($this, RC::EXCEPTION_BIT_VALUE, function($test) {
$test->redis->setbit('binary', 15, 'invalid');
});
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->rpush('metavars', 'foo');
$test->redis->setbit('metavars', 0, 1);
});
}
function testStrlen() {
$this->redis->set('var', 'foobar');
$this->assertEquals(6, $this->redis->strlen('var'));