Преглед изворни кода

Add DUMP and RESTORE to the server profile for Redis 2.6.

Closes issue #108.
Daniele Alessandri пре 12 година
родитељ
комит
531261b0fc

+ 2 - 0
CHANGELOG.md

@@ -1,6 +1,8 @@
 v0.8.4 (2013-xx-xx)
 ===============================================================================
 
+- Added `DUMP` and `RESTORE` to the server profile for Redis 2.6.
+
 - __FIX__: allow `HMSET` when using a cluster of Redis nodes with client-side
   sharding or redis-cluster (ISSUE #106).
 

+ 27 - 0
lib/Predis/Command/KeyDump.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+/**
+ * @link http://redis.io/commands/dump
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+class KeyDump extends PrefixableCommand
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getId()
+    {
+        return 'DUMP';
+    }
+}

+ 27 - 0
lib/Predis/Command/KeyRestore.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+/**
+ * @link http://redis.io/commands/restore
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+class KeyRestore extends PrefixableCommand
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getId()
+    {
+        return 'RESTORE';
+    }
+}

+ 2 - 0
lib/Predis/Profile/ServerVersion26.php

@@ -47,6 +47,8 @@ class ServerVersion26 extends ServerProfile
             'ttl'                       => 'Predis\Command\KeyTimeToLive',
             'move'                      => 'Predis\Command\KeyMove',
             'sort'                      => 'Predis\Command\KeySort',
+            'dump'                      => 'Predis\Command\KeyDump',
+            'restore'                   => 'Predis\Command\KeyRestore',
 
             /* commands operating on string values */
             'set'                       => 'Predis\Command\StringSet',

+ 78 - 0
tests/Predis/Command/KeyDumpTest.php

@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+use \PHPUnit_Framework_TestCase as StandardTestCase;
+
+/**
+ * @group commands
+ * @group realm-key
+ */
+class KeyDumpTest extends CommandTestCase
+{
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedCommand()
+    {
+        return 'Predis\Command\KeyDump';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedId()
+    {
+        return 'DUMP';
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testFilterArguments()
+    {
+        $arguments = array('key');
+        $expected = array('key');
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testParseResponse()
+    {
+        $raw = "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(";
+        $expected = "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(";
+
+        $command = $this->getCommand();
+
+        $this->assertSame($expected, $command->parseResponse($raw));
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testPrefixKeys()
+    {
+        $arguments = array('key');
+        $expected = array('prefix:key');
+
+        $command = $this->getCommandWithArgumentsArray($arguments);
+        $command->prefixKeys('prefix:');
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+}

+ 73 - 0
tests/Predis/Command/KeyRestoreTest.php

@@ -0,0 +1,73 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+use \PHPUnit_Framework_TestCase as StandardTestCase;
+
+/**
+ * @group commands
+ * @group realm-key
+ */
+class KeyRestoreTest extends CommandTestCase
+{
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedCommand()
+    {
+        return 'Predis\Command\KeyRestore';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedId()
+    {
+        return 'RESTORE';
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testFilterArguments()
+    {
+        $arguments = array('key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(");
+        $expected = array('key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(");
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testParseResponse()
+    {
+        $this->assertTrue($this->getCommand()->parseResponse(true));
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testPrefixKeys()
+    {
+        $arguments = array('key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(");
+        $expected = array('prefix:key', 0, "\x00\xC0\n\x06\x00\xF8r?\xC5\xFB\xFB_(");
+
+        $command = $this->getCommandWithArgumentsArray($arguments);
+        $command->prefixKeys('prefix:');
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+}

+ 123 - 121
tests/Predis/Profile/ServerVersion26Test.php

@@ -50,127 +50,129 @@ class ServerVersion26Test extends ServerVersionTestCase
             9 => 'ttl',
             10 => 'move',
             11 => 'sort',
-            12 => 'set',
-            13 => 'setnx',
-            14 => 'mset',
-            15 => 'msetnx',
-            16 => 'get',
-            17 => 'mget',
-            18 => 'getset',
-            19 => 'incr',
-            20 => 'incrby',
-            21 => 'decr',
-            22 => 'decrby',
-            23 => 'rpush',
-            24 => 'lpush',
-            25 => 'llen',
-            26 => 'lrange',
-            27 => 'ltrim',
-            28 => 'lindex',
-            29 => 'lset',
-            30 => 'lrem',
-            31 => 'lpop',
-            32 => 'rpop',
-            33 => 'rpoplpush',
-            34 => 'sadd',
-            35 => 'srem',
-            36 => 'spop',
-            37 => 'smove',
-            38 => 'scard',
-            39 => 'sismember',
-            40 => 'sinter',
-            41 => 'sinterstore',
-            42 => 'sunion',
-            43 => 'sunionstore',
-            44 => 'sdiff',
-            45 => 'sdiffstore',
-            46 => 'smembers',
-            47 => 'srandmember',
-            48 => 'zadd',
-            49 => 'zincrby',
-            50 => 'zrem',
-            51 => 'zrange',
-            52 => 'zrevrange',
-            53 => 'zrangebyscore',
-            54 => 'zcard',
-            55 => 'zscore',
-            56 => 'zremrangebyscore',
-            57 => 'ping',
-            58 => 'auth',
-            59 => 'select',
-            60 => 'echo',
-            61 => 'quit',
-            62 => 'info',
-            63 => 'slaveof',
-            64 => 'monitor',
-            65 => 'dbsize',
-            66 => 'flushdb',
-            67 => 'flushall',
-            68 => 'save',
-            69 => 'bgsave',
-            70 => 'lastsave',
-            71 => 'shutdown',
-            72 => 'bgrewriteaof',
-            73 => 'setex',
-            74 => 'append',
-            75 => 'substr',
-            76 => 'blpop',
-            77 => 'brpop',
-            78 => 'zunionstore',
-            79 => 'zinterstore',
-            80 => 'zcount',
-            81 => 'zrank',
-            82 => 'zrevrank',
-            83 => 'zremrangebyrank',
-            84 => 'hset',
-            85 => 'hsetnx',
-            86 => 'hmset',
-            87 => 'hincrby',
-            88 => 'hget',
-            89 => 'hmget',
-            90 => 'hdel',
-            91 => 'hexists',
-            92 => 'hlen',
-            93 => 'hkeys',
-            94 => 'hvals',
-            95 => 'hgetall',
-            96 => 'multi',
-            97 => 'exec',
-            98 => 'discard',
-            99 => 'subscribe',
-            100 => 'unsubscribe',
-            101 => 'psubscribe',
-            102 => 'punsubscribe',
-            103 => 'publish',
-            104 => 'config',
-            105 => 'persist',
-            106 => 'strlen',
-            107 => 'setrange',
-            108 => 'getrange',
-            109 => 'setbit',
-            110 => 'getbit',
-            111 => 'rpushx',
-            112 => 'lpushx',
-            113 => 'linsert',
-            114 => 'brpoplpush',
-            115 => 'zrevrangebyscore',
-            116 => 'watch',
-            117 => 'unwatch',
-            118 => 'object',
-            119 => 'slowlog',
-            120 => 'client',
-            121 => 'pttl',
-            122 => 'pexpire',
-            123 => 'pexpireat',
-            124 => 'psetex',
-            125 => 'incrbyfloat',
-            126 => 'bitop',
-            127 => 'bitcount',
-            128 => 'hincrbyfloat',
-            129 => 'eval',
-            130 => 'evalsha',
-            131 => 'script',
-            132 => 'time',
+            12 => 'dump',
+            13 => 'restore',
+            14 => 'set',
+            15 => 'setnx',
+            16 => 'mset',
+            17 => 'msetnx',
+            18 => 'get',
+            19 => 'mget',
+            20 => 'getset',
+            21 => 'incr',
+            22 => 'incrby',
+            23 => 'decr',
+            24 => 'decrby',
+            25 => 'rpush',
+            26 => 'lpush',
+            27 => 'llen',
+            28 => 'lrange',
+            29 => 'ltrim',
+            30 => 'lindex',
+            31 => 'lset',
+            32 => 'lrem',
+            33 => 'lpop',
+            34 => 'rpop',
+            35 => 'rpoplpush',
+            36 => 'sadd',
+            37 => 'srem',
+            38 => 'spop',
+            39 => 'smove',
+            40 => 'scard',
+            41 => 'sismember',
+            42 => 'sinter',
+            43 => 'sinterstore',
+            44 => 'sunion',
+            45 => 'sunionstore',
+            46 => 'sdiff',
+            47 => 'sdiffstore',
+            48 => 'smembers',
+            49 => 'srandmember',
+            50 => 'zadd',
+            51 => 'zincrby',
+            52 => 'zrem',
+            53 => 'zrange',
+            54 => 'zrevrange',
+            55 => 'zrangebyscore',
+            56 => 'zcard',
+            57 => 'zscore',
+            58 => 'zremrangebyscore',
+            59 => 'ping',
+            60 => 'auth',
+            61 => 'select',
+            62 => 'echo',
+            63 => 'quit',
+            64 => 'info',
+            65 => 'slaveof',
+            66 => 'monitor',
+            67 => 'dbsize',
+            68 => 'flushdb',
+            69 => 'flushall',
+            70 => 'save',
+            71 => 'bgsave',
+            72 => 'lastsave',
+            73 => 'shutdown',
+            74 => 'bgrewriteaof',
+            75 => 'setex',
+            76 => 'append',
+            77 => 'substr',
+            78 => 'blpop',
+            79 => 'brpop',
+            80 => 'zunionstore',
+            81 => 'zinterstore',
+            82 => 'zcount',
+            83 => 'zrank',
+            84 => 'zrevrank',
+            85 => 'zremrangebyrank',
+            86 => 'hset',
+            87 => 'hsetnx',
+            88 => 'hmset',
+            89 => 'hincrby',
+            90 => 'hget',
+            91 => 'hmget',
+            92 => 'hdel',
+            93 => 'hexists',
+            94 => 'hlen',
+            95 => 'hkeys',
+            96 => 'hvals',
+            97 => 'hgetall',
+            98 => 'multi',
+            99 => 'exec',
+            100 => 'discard',
+            101 => 'subscribe',
+            102 => 'unsubscribe',
+            103 => 'psubscribe',
+            104 => 'punsubscribe',
+            105 => 'publish',
+            106 => 'config',
+            107 => 'persist',
+            108 => 'strlen',
+            109 => 'setrange',
+            110 => 'getrange',
+            111 => 'setbit',
+            112 => 'getbit',
+            113 => 'rpushx',
+            114 => 'lpushx',
+            115 => 'linsert',
+            116 => 'brpoplpush',
+            117 => 'zrevrangebyscore',
+            118 => 'watch',
+            119 => 'unwatch',
+            120 => 'object',
+            121 => 'slowlog',
+            122 => 'client',
+            123 => 'pttl',
+            124 => 'pexpire',
+            125 => 'pexpireat',
+            126 => 'psetex',
+            127 => 'incrbyfloat',
+            128 => 'bitop',
+            129 => 'bitcount',
+            130 => 'hincrbyfloat',
+            131 => 'eval',
+            132 => 'evalsha',
+            133 => 'script',
+            134 => 'time',
         );
     }
 }

+ 123 - 121
tests/Predis/Profile/ServerVersionNextTest.php

@@ -50,127 +50,129 @@ class ServerVersionNextTest extends ServerVersionTestCase
             9 => 'ttl',
             10 => 'move',
             11 => 'sort',
-            12 => 'set',
-            13 => 'setnx',
-            14 => 'mset',
-            15 => 'msetnx',
-            16 => 'get',
-            17 => 'mget',
-            18 => 'getset',
-            19 => 'incr',
-            20 => 'incrby',
-            21 => 'decr',
-            22 => 'decrby',
-            23 => 'rpush',
-            24 => 'lpush',
-            25 => 'llen',
-            26 => 'lrange',
-            27 => 'ltrim',
-            28 => 'lindex',
-            29 => 'lset',
-            30 => 'lrem',
-            31 => 'lpop',
-            32 => 'rpop',
-            33 => 'rpoplpush',
-            34 => 'sadd',
-            35 => 'srem',
-            36 => 'spop',
-            37 => 'smove',
-            38 => 'scard',
-            39 => 'sismember',
-            40 => 'sinter',
-            41 => 'sinterstore',
-            42 => 'sunion',
-            43 => 'sunionstore',
-            44 => 'sdiff',
-            45 => 'sdiffstore',
-            46 => 'smembers',
-            47 => 'srandmember',
-            48 => 'zadd',
-            49 => 'zincrby',
-            50 => 'zrem',
-            51 => 'zrange',
-            52 => 'zrevrange',
-            53 => 'zrangebyscore',
-            54 => 'zcard',
-            55 => 'zscore',
-            56 => 'zremrangebyscore',
-            57 => 'ping',
-            58 => 'auth',
-            59 => 'select',
-            60 => 'echo',
-            61 => 'quit',
-            62 => 'info',
-            63 => 'slaveof',
-            64 => 'monitor',
-            65 => 'dbsize',
-            66 => 'flushdb',
-            67 => 'flushall',
-            68 => 'save',
-            69 => 'bgsave',
-            70 => 'lastsave',
-            71 => 'shutdown',
-            72 => 'bgrewriteaof',
-            73 => 'setex',
-            74 => 'append',
-            75 => 'substr',
-            76 => 'blpop',
-            77 => 'brpop',
-            78 => 'zunionstore',
-            79 => 'zinterstore',
-            80 => 'zcount',
-            81 => 'zrank',
-            82 => 'zrevrank',
-            83 => 'zremrangebyrank',
-            84 => 'hset',
-            85 => 'hsetnx',
-            86 => 'hmset',
-            87 => 'hincrby',
-            88 => 'hget',
-            89 => 'hmget',
-            90 => 'hdel',
-            91 => 'hexists',
-            92 => 'hlen',
-            93 => 'hkeys',
-            94 => 'hvals',
-            95 => 'hgetall',
-            96 => 'multi',
-            97 => 'exec',
-            98 => 'discard',
-            99 => 'subscribe',
-            100 => 'unsubscribe',
-            101 => 'psubscribe',
-            102 => 'punsubscribe',
-            103 => 'publish',
-            104 => 'config',
-            105 => 'persist',
-            106 => 'strlen',
-            107 => 'setrange',
-            108 => 'getrange',
-            109 => 'setbit',
-            110 => 'getbit',
-            111 => 'rpushx',
-            112 => 'lpushx',
-            113 => 'linsert',
-            114 => 'brpoplpush',
-            115 => 'zrevrangebyscore',
-            116 => 'watch',
-            117 => 'unwatch',
-            118 => 'object',
-            119 => 'slowlog',
-            120 => 'client',
-            121 => 'pttl',
-            122 => 'pexpire',
-            123 => 'pexpireat',
-            124 => 'psetex',
-            125 => 'incrbyfloat',
-            126 => 'bitop',
-            127 => 'bitcount',
-            128 => 'hincrbyfloat',
-            129 => 'eval',
-            130 => 'evalsha',
-            131 => 'script',
-            132 => 'time',
+            12 => 'dump',
+            13 => 'restore',
+            14 => 'set',
+            15 => 'setnx',
+            16 => 'mset',
+            17 => 'msetnx',
+            18 => 'get',
+            19 => 'mget',
+            20 => 'getset',
+            21 => 'incr',
+            22 => 'incrby',
+            23 => 'decr',
+            24 => 'decrby',
+            25 => 'rpush',
+            26 => 'lpush',
+            27 => 'llen',
+            28 => 'lrange',
+            29 => 'ltrim',
+            30 => 'lindex',
+            31 => 'lset',
+            32 => 'lrem',
+            33 => 'lpop',
+            34 => 'rpop',
+            35 => 'rpoplpush',
+            36 => 'sadd',
+            37 => 'srem',
+            38 => 'spop',
+            39 => 'smove',
+            40 => 'scard',
+            41 => 'sismember',
+            42 => 'sinter',
+            43 => 'sinterstore',
+            44 => 'sunion',
+            45 => 'sunionstore',
+            46 => 'sdiff',
+            47 => 'sdiffstore',
+            48 => 'smembers',
+            49 => 'srandmember',
+            50 => 'zadd',
+            51 => 'zincrby',
+            52 => 'zrem',
+            53 => 'zrange',
+            54 => 'zrevrange',
+            55 => 'zrangebyscore',
+            56 => 'zcard',
+            57 => 'zscore',
+            58 => 'zremrangebyscore',
+            59 => 'ping',
+            60 => 'auth',
+            61 => 'select',
+            62 => 'echo',
+            63 => 'quit',
+            64 => 'info',
+            65 => 'slaveof',
+            66 => 'monitor',
+            67 => 'dbsize',
+            68 => 'flushdb',
+            69 => 'flushall',
+            70 => 'save',
+            71 => 'bgsave',
+            72 => 'lastsave',
+            73 => 'shutdown',
+            74 => 'bgrewriteaof',
+            75 => 'setex',
+            76 => 'append',
+            77 => 'substr',
+            78 => 'blpop',
+            79 => 'brpop',
+            80 => 'zunionstore',
+            81 => 'zinterstore',
+            82 => 'zcount',
+            83 => 'zrank',
+            84 => 'zrevrank',
+            85 => 'zremrangebyrank',
+            86 => 'hset',
+            87 => 'hsetnx',
+            88 => 'hmset',
+            89 => 'hincrby',
+            90 => 'hget',
+            91 => 'hmget',
+            92 => 'hdel',
+            93 => 'hexists',
+            94 => 'hlen',
+            95 => 'hkeys',
+            96 => 'hvals',
+            97 => 'hgetall',
+            98 => 'multi',
+            99 => 'exec',
+            100 => 'discard',
+            101 => 'subscribe',
+            102 => 'unsubscribe',
+            103 => 'psubscribe',
+            104 => 'punsubscribe',
+            105 => 'publish',
+            106 => 'config',
+            107 => 'persist',
+            108 => 'strlen',
+            109 => 'setrange',
+            110 => 'getrange',
+            111 => 'setbit',
+            112 => 'getbit',
+            113 => 'rpushx',
+            114 => 'lpushx',
+            115 => 'linsert',
+            116 => 'brpoplpush',
+            117 => 'zrevrangebyscore',
+            118 => 'watch',
+            119 => 'unwatch',
+            120 => 'object',
+            121 => 'slowlog',
+            122 => 'client',
+            123 => 'pttl',
+            124 => 'pexpire',
+            125 => 'pexpireat',
+            126 => 'psetex',
+            127 => 'incrbyfloat',
+            128 => 'bitop',
+            129 => 'bitcount',
+            130 => 'hincrbyfloat',
+            131 => 'eval',
+            132 => 'evalsha',
+            133 => 'script',
+            134 => 'time',
         );
     }
 }