Quellcode durchsuchen

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

Daniele Alessandri vor 14 Jahren
Ursprung
Commit
73b4760fc4
2 geänderte Dateien mit 20 neuen und 0 gelöschten Zeilen
  1. 7 0
      lib/Predis.php
  2. 13 0
      test/RedisCommandsTest.php

+ 7 - 0
lib/Predis.php

@@ -1746,6 +1746,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',
         ));
     }
 }
@@ -2290,6 +2293,10 @@ class Substr extends Command {
     public function getCommandId() { return 'SUBSTR'; }
 }
 
+class Strlen extends Command {
+    public function getCommandId() { return 'STRLEN'; }
+}
+
 /* commands operating on the key space */
 class Keys extends Command {
     public function canBeHashed()  { return false; }

+ 13 - 0
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() {