Quellcode durchsuchen

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

Daniele Alessandri vor 14 Jahren
Ursprung
Commit
49a140e3af
2 geänderte Dateien mit 23 neuen und 0 gelöschten Zeilen
  1. 7 0
      lib/Predis.php
  2. 16 0
      test/RedisCommandsTest.php

+ 7 - 0
lib/Predis.php

@@ -1749,6 +1749,9 @@ class RedisServer_vNext extends RedisServer_v2_0 {
 
             /* commands operating on string values */
             'strlen'                    => '\Predis\Commands\Strlen',
+
+            /* commands operating on lists */
+            'linsert'                   => '\Predis\Commands\ListInsert',
         ));
     }
 }
@@ -2403,6 +2406,10 @@ class ListPopLastBlocking extends Command {
     public function getCommandId() { return 'BRPOP'; }
 }
 
+class ListInsert extends Command {
+    public function getCommandId() { return 'LINSERT'; }
+}
+
 /* commands operating on sets */
 class SetAdd extends Command {
     public function getCommandId() { return 'SADD'; }

+ 16 - 0
test/RedisCommandsTest.php

@@ -693,6 +693,22 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertEquals((float)(time() - $start), 2, '', 1);
     }
 
+    function testListInsert() {
+        $numbers = RC::pushTailAndReturn($this->redis, 'numbers', RC::getArrayOfNumbers());
+
+        $this->assertEquals(11, $this->redis->linsert('numbers', 'before', 0, -2));
+        $this->assertEquals(12, $this->redis->linsert('numbers', 'after', -2, -1));
+        $this->assertEquals(array(-2, -1, 0, 1), $this->redis->lrange('numbers', 0, 3));
+
+        $this->assertEquals(-1, $this->redis->linsert('numbers', 'after', 100, 200));
+        $this->assertEquals(-1, $this->redis->linsert('numbers', 'before', 100, 50));
+
+        RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
+            $test->redis->set('foo', 'bar');
+            $test->redis->lset('foo', 0, 0);
+        });
+    }
+
 
     /* commands operating on sets */