Forráskód Böngészése

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

Daniele Alessandri 14 éve
szülő
commit
fb5f878e21
2 módosított fájl, 27 hozzáadás és 0 törlés
  1. 5 0
      lib/Predis.php
  2. 22 0
      test/RedisCommandsTest.php

+ 5 - 0
lib/Predis.php

@@ -1826,6 +1826,7 @@ class RedisServer_vNext extends RedisServer_v2_0 {
             'setrange'                  => '\Predis\Commands\SetRange',
             'getrange'                  => '\Predis\Commands\Substr',
             'setbit'                    => '\Predis\Commands\SetBit',
+            'getbit'                    => '\Predis\Commands\GetBit',
 
             /* commands operating on the key space */
             'persist'                   => '\Predis\Commands\Persist',
@@ -2372,6 +2373,10 @@ class SetBit extends \Predis\MultiBulkCommand {
     public function getCommandId() { return 'SETBIT'; }
 }
 
+class GetBit extends \Predis\MultiBulkCommand {
+    public function getCommandId() { return 'GETBIT'; }
+}
+
 class Strlen extends \Predis\MultiBulkCommand {
     public function getCommandId() { return 'STRLEN'; }
 }

+ 22 - 0
test/RedisCommandsTest.php

@@ -294,6 +294,28 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
         });
     }
 
+    function testGetBit() {
+        $this->redis->set('binary', "\x80\x00\00\x01");
+
+        $this->assertEquals(1, $this->redis->getbit('binary', 0));
+        $this->assertEquals(0, $this->redis->getbit('binary', 15));
+        $this->assertEquals(1, $this->redis->getbit('binary', 31));
+        $this->assertEquals(0, $this->redis->getbit('binary', 63));
+
+        RC::testForServerException($this, RC::EXCEPTION_BIT_OFFSET, function($test) {
+            $test->redis->getbit('binary', -1);
+        });
+
+        RC::testForServerException($this, RC::EXCEPTION_BIT_OFFSET, function($test) {
+            $test->redis->getbit('binary', 'invalid');
+        });
+
+        RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
+            $test->redis->rpush('metavars', 'foo');
+            $test->redis->getbit('metavars', 0);
+        });
+    }
+
     function testStrlen() {
         $this->redis->set('var', 'foobar');
         $this->assertEquals(6, $this->redis->strlen('var'));