From 9ae47c865ec45d175f743b393ef5f9ff2bb786f6 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 25 Sep 2010 16:31:35 +0200 Subject: [PATCH] New command: STRLEN (Redis v2.2-dev). --- lib/Predis.php | 7 +++++++ test/RedisCommandsTest.php | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/Predis.php b/lib/Predis.php index 797d8a47..23802c99 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -1811,6 +1811,9 @@ class RedisServer_vNext extends RedisServer_v2_0 { /* transactions */ 'watch' => '\Predis\Commands\Watch', 'unwatch' => '\Predis\Commands\Unwatch', + + /* commands operating on string values */ + 'strlen' => '\Predis\Commands\Strlen', )); } } @@ -2338,6 +2341,10 @@ class Substr extends \Predis\MultiBulkCommand { public function getCommandId() { return 'SUBSTR'; } } +class Strlen extends \Predis\MultiBulkCommand { + public function getCommandId() { return 'STRLEN'; } +} + /* commands operating on the key space */ class Keys extends \Predis\MultiBulkCommand { public function canBeHashed() { return false; } diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index cc9db5be..ed891123 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -240,6 +240,19 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { }); } + function testStrlen() { + $this->redis->set('var', 'foobar'); + $this->assertEquals(6, $this->redis->strlen('var')); + $this->assertEquals(9, $this->redis->append('var', '___')); + $this->assertEquals(9, $this->redis->strlen('var')); + + RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) { + $test->redis->rpush('metavars', 'foo'); + $test->redis->strlen('metavars'); + }); + } + + /* commands operating on the key space */ function testKeys() {