mirror of
https://github.com/predis/predis.git
synced 2026-09-14 20:37:29 +00:00
New command: SETBIT (Redis v2.2-dev).
Conflicts: lib/Predis.php
This commit is contained in:
@@ -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'; }
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user