mirror of
https://github.com/predis/predis.git
synced 2026-09-19 14:56:57 +00:00
New command: SETRANGE (Redis v2.2-dev).
This commit is contained in:
@@ -1823,6 +1823,7 @@ class RedisServer_vNext extends RedisServer_v2_0 {
|
||||
|
||||
/* commands operating on string values */
|
||||
'strlen' => '\Predis\Commands\Strlen',
|
||||
'setrange' => '\Predis\Commands\SetRange',
|
||||
'getrange' => '\Predis\Commands\Substr',
|
||||
|
||||
/* commands operating on the key space */
|
||||
@@ -2358,6 +2359,10 @@ class Append extends \Predis\MultiBulkCommand {
|
||||
public function getCommandId() { return 'APPEND'; }
|
||||
}
|
||||
|
||||
class SetRange extends \Predis\MultiBulkCommand {
|
||||
public function getCommandId() { return 'SETRANGE'; }
|
||||
}
|
||||
|
||||
class Substr extends \Predis\MultiBulkCommand {
|
||||
public function getCommandId() { return 'SUBSTR'; }
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ class RC {
|
||||
const EXCEPTION_WRONG_TYPE = 'Operation against a key holding the wrong kind of value';
|
||||
const EXCEPTION_NO_SUCH_KEY = 'no such key';
|
||||
const EXCEPTION_OUT_OF_RANGE = 'index out of range';
|
||||
const EXCEPTION_OFFSET_RANGE = 'offset is out of range';
|
||||
const EXCEPTION_INVALID_DB_IDX = 'invalid DB index';
|
||||
const EXCEPTION_VALUE_NOT_INT = 'value is not an integer';
|
||||
const EXCEPTION_EXEC_NO_MULTI = 'EXEC without MULTI';
|
||||
|
||||
@@ -223,6 +223,28 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testSetRange() {
|
||||
$this->assertEquals(6, $this->redis->setrange('var', 0, 'foobar'));
|
||||
$this->assertEquals('foobar', $this->redis->get('var'));
|
||||
$this->assertEquals(6, $this->redis->setrange('var', 3, 'foo'));
|
||||
$this->assertEquals('foofoo', $this->redis->get('var'));
|
||||
$this->assertEquals(16, $this->redis->setrange('var', 10, 'barbar'));
|
||||
$this->assertEquals("foofoo\x00\x00\x00\x00barbar", $this->redis->get('var'));
|
||||
|
||||
$this->assertEquals(4, $this->redis->setrange('binary', 0, pack('l', -2147483648)));
|
||||
list($unpacked) = array_values(unpack('l', $this->redis->get('binary')));
|
||||
$this->assertEquals(-2147483648, $unpacked);
|
||||
|
||||
RC::testForServerException($this, RC::EXCEPTION_OFFSET_RANGE, function($test) {
|
||||
$test->redis->setrange('var', -1, 'bogus');
|
||||
});
|
||||
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
|
||||
$test->redis->rpush('metavars', 'foo');
|
||||
$test->redis->setrange('metavars', 0, 'hoge');
|
||||
});
|
||||
}
|
||||
|
||||
function testSubstr() {
|
||||
$this->redis->set('var', 'foobar');
|
||||
$this->assertEquals('foo', $this->redis->substr('var', 0, 2));
|
||||
|
||||
Reference in New Issue
Block a user