ソースを参照

Merge branch 'cmd_zincrby'

Daniele Alessandri 15 年 前
コミット
d9b304f9e3
2 ファイル変更26 行追加0 行削除
  1. 6 0
      lib/Predis.php
  2. 20 0
      test/RedisCommandsTest.php

+ 6 - 0
lib/Predis.php

@@ -274,6 +274,8 @@ class Client {
             /* commands operating on sorted sets */
             'zadd'                          => '\Predis\Commands\ZSetAdd', 
                 'zsetAdd'                   => '\Predis\Commands\ZSetAdd',
+            'zincrby'                       => '\Predis\Commands\ZSetIncrementBy', 
+                'zsetIncrementBy'           => '\Predis\Commands\ZSetIncrementBy', 
             'zrem'                          => '\Predis\Commands\ZSetRemove', 
                 'zsetRemove'                => '\Predis\Commands\ZSetRemove',
             'zrange'                        => '\Predis\Commands\ZSetRange', 
@@ -1139,6 +1141,10 @@ class ZSetAdd extends \Predis\BulkCommand {
     public function parseResponse($data) { return (bool) $data; }
 }
 
+class ZSetIncrementBy extends \Predis\BulkCommand {
+    public function getCommandId() { return 'ZINCRBY'; }
+}
+
 class ZSetRemove extends \Predis\BulkCommand {
     public function getCommandId() { return 'ZREM'; }
     public function parseResponse($data) { return (bool) $data; }

+ 20 - 0
test/RedisCommandsTest.php

@@ -866,6 +866,26 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
         });
     }
 
+    function testZsetIncrementBy() {
+        $this->assertEquals(1, $this->redis->zsetIncrementBy('zsetDoesNotExist', 1, 'foo'));
+        $this->assertEquals('zset', $this->redis->type('zsetDoesNotExist'));
+
+        RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());
+        $this->assertEquals(-5, $this->redis->zsetIncrementBy('zset', 5, 'a'));
+        $this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'b'));
+        $this->assertEquals(10, $this->redis->zsetIncrementBy('zset', 0, 'c'));
+        $this->assertEquals(0, $this->redis->zsetIncrementBy('zset', -20, 'd'));
+        $this->assertEquals(2, $this->redis->zsetIncrementBy('zset', 2, 'd'));
+        $this->assertEquals(-10, $this->redis->zsetIncrementBy('zset', -30, 'e'));
+        $this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'x'));
+
+        // wrong type
+        $this->redis->set('foo', 'bar');
+        RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
+            $test->redis->zsetIncrementBy('foo', 1, 'a');
+        });
+    }
+
     function testZsetRemove() {
         RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());