Эх сурвалжийг харах

Handle key prefixing in a more consistent way, and make it a first-class citizen in Predis.

Daniele Alessandri 14 жил өмнө
parent
commit
5a80876c64
46 өөрчлөгдсөн 225 нэмэгдсэн , 156 устгасан
  1. 13 0
      lib/Predis/Commands/Command.php
  2. 4 0
      lib/Predis/Commands/ConnectionAuth.php
  3. 4 0
      lib/Predis/Commands/ConnectionEcho.php
  4. 4 0
      lib/Predis/Commands/ConnectionPing.php
  5. 4 0
      lib/Predis/Commands/ConnectionQuit.php
  6. 4 0
      lib/Predis/Commands/ConnectionSelect.php
  7. 1 0
      lib/Predis/Commands/ICommand.php
  8. 4 0
      lib/Predis/Commands/KeyDelete.php
  9. 4 0
      lib/Predis/Commands/KeyRename.php
  10. 1 5
      lib/Predis/Commands/KeyRenamePreserve.php
  11. 24 0
      lib/Predis/Commands/KeySort.php
  12. 4 0
      lib/Predis/Commands/ListPopFirstBlocking.php
  13. 4 0
      lib/Predis/Commands/ListPopLastPushHead.php
  14. 4 0
      lib/Predis/Commands/ListPopLastPushHeadBlocking.php
  15. 20 0
      lib/Predis/Commands/PrefixHelpers.php
  16. 3 137
      lib/Predis/Commands/Processors/KeyPrefixProcessor.php
  17. 4 0
      lib/Predis/Commands/PubSubSubscribe.php
  18. 1 9
      lib/Predis/Commands/PubSubSubscribeByPattern.php
  19. 4 0
      lib/Predis/Commands/PubSubUnsubscribe.php
  20. 1 5
      lib/Predis/Commands/PubSubUnsubscribeByPattern.php
  21. 4 0
      lib/Predis/Commands/ServerBackgroundRewriteAOF.php
  22. 4 0
      lib/Predis/Commands/ServerBackgroundSave.php
  23. 4 0
      lib/Predis/Commands/ServerClient.php
  24. 4 0
      lib/Predis/Commands/ServerConfig.php
  25. 4 0
      lib/Predis/Commands/ServerDatabaseSize.php
  26. 4 0
      lib/Predis/Commands/ServerFlushAll.php
  27. 4 0
      lib/Predis/Commands/ServerFlushDatabase.php
  28. 4 0
      lib/Predis/Commands/ServerInfo.php
  29. 4 0
      lib/Predis/Commands/ServerLastSave.php
  30. 4 0
      lib/Predis/Commands/ServerMonitor.php
  31. 4 0
      lib/Predis/Commands/ServerObject.php
  32. 4 0
      lib/Predis/Commands/ServerSave.php
  33. 4 0
      lib/Predis/Commands/ServerShutdown.php
  34. 4 0
      lib/Predis/Commands/ServerSlaveOf.php
  35. 4 0
      lib/Predis/Commands/SetDifference.php
  36. 4 0
      lib/Predis/Commands/SetIntersection.php
  37. 4 0
      lib/Predis/Commands/SetIntersectionStore.php
  38. 4 0
      lib/Predis/Commands/SetMove.php
  39. 4 0
      lib/Predis/Commands/StringGetMultiple.php
  40. 8 0
      lib/Predis/Commands/StringSetMultiple.php
  41. 4 0
      lib/Predis/Commands/TransactionDiscard.php
  42. 4 0
      lib/Predis/Commands/TransactionExec.php
  43. 4 0
      lib/Predis/Commands/TransactionMulti.php
  44. 4 0
      lib/Predis/Commands/TransactionUnwatch.php
  45. 4 0
      lib/Predis/Commands/TransactionWatch.php
  46. 9 0
      lib/Predis/Commands/ZSetUnionStore.php

+ 13 - 0
lib/Predis/Commands/Command.php

@@ -28,6 +28,19 @@ abstract class Command implements ICommand {
         }
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        $arguments[0] = "$prefix{$arguments[0]}";
+        return $arguments;
+    }
+
+    public function prefixKeys($prefix) {
+        $arguments = $this->onPrefixKeys($this->_arguments, $prefix);
+        if (isset($arguments)) {
+            $this->_arguments = $arguments;
+            unset($this->_hash);
+        }
+    }
+
     protected function canBeHashed() {
         return isset($this->_arguments[0]);
     }

+ 4 - 0
lib/Predis/Commands/ConnectionAuth.php

@@ -7,6 +7,10 @@ class ConnectionAuth extends Command {
         return 'AUTH';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ConnectionEcho.php

@@ -7,6 +7,10 @@ class ConnectionEcho extends Command {
         return 'ECHO';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ConnectionPing.php

@@ -7,6 +7,10 @@ class ConnectionPing extends Command {
         return 'PING';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ConnectionQuit.php

@@ -7,6 +7,10 @@ class ConnectionQuit extends Command {
         return 'QUIT';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ConnectionSelect.php

@@ -7,6 +7,10 @@ class ConnectionSelect extends Command {
         return 'SELECT';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 1 - 0
lib/Predis/Commands/ICommand.php

@@ -9,5 +9,6 @@ interface ICommand {
     public function getHash(INodeKeyGenerator $distributor);
     public function setArguments(Array $arguments);
     public function getArguments();
+    public function prefixKeys($prefix);
     public function parseResponse($data);
 }

+ 4 - 0
lib/Predis/Commands/KeyDelete.php

@@ -13,6 +13,10 @@ class KeyDelete extends Command {
         return Helpers::filterArrayArguments($arguments);
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         $args = $this->getArguments();
         if (count($args) === 1) {

+ 4 - 0
lib/Predis/Commands/KeyRename.php

@@ -7,6 +7,10 @@ class KeyRename extends Command {
         return 'RENAME';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 1 - 5
lib/Predis/Commands/KeyRenamePreserve.php

@@ -2,15 +2,11 @@
 
 namespace Predis\Commands;
 
-class KeyRenamePreserve extends Command {
+class KeyRenamePreserve extends KeyRename {
     public function getId() {
         return 'RENAMENX';
     }
 
-    protected function canBeHashed() {
-        return false;
-    }
-
     public function parseResponse($data) {
         return (bool) $data;
     }

+ 24 - 0
lib/Predis/Commands/KeySort.php

@@ -52,4 +52,28 @@ class KeySort extends Command {
 
         return $query;
     }
+
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        $arguments[0] = "$prefix{$arguments[0]}";
+        if (($count = count($arguments)) > 1) {
+            for ($i = 1; $i < $count; $i++) {
+                switch ($arguments[$i]) {
+                    case 'BY':
+                    case 'STORE':
+                        $arguments[$i] = "$prefix{$arguments[++$i]}";
+                        break;
+                    case 'GET':
+                        $value = $arguments[++$i];
+                        if ($value !== '#') {
+                            $arguments[$i] = "$prefix$value";
+                        }
+                        break;
+                    case 'LIMIT';
+                        $i += 2;
+                        break;
+                }
+            }
+        }
+        return $arguments;
+    }
 }

+ 4 - 0
lib/Predis/Commands/ListPopFirstBlocking.php

@@ -7,6 +7,10 @@ class ListPopFirstBlocking extends Command {
         return 'BLPOP';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::skipLastArgument($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys(
             array_slice(($args = $this->getArguments()), 0, count($args) - 1)

+ 4 - 0
lib/Predis/Commands/ListPopLastPushHead.php

@@ -7,6 +7,10 @@ class ListPopLastPushHead extends Command {
         return 'RPOPLPUSH';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys($this->getArguments());
     }

+ 4 - 0
lib/Predis/Commands/ListPopLastPushHeadBlocking.php

@@ -7,6 +7,10 @@ class ListPopLastPushHeadBlocking extends Command {
         return 'BRPOPLPUSH';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::skipLastArgument($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys(
             array_slice($args = $this->getArguments(), 0, count($args) - 1)

+ 20 - 0
lib/Predis/Commands/PrefixHelpers.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Predis\Commands;
+
+class PrefixHelpers {
+    public static function multipleKeys(Array $arguments, $prefix) {
+        foreach ($arguments as &$key) {
+            $key = "$prefix$key";
+        }
+        return $arguments;
+    }
+
+    public static function skipLastArgument(Array $arguments, $prefix) {
+        $length = count($arguments);
+        for ($i = 0; $i < $length - 1; $i++) {
+            $arguments[$i] = "$prefix{$arguments[$i]}";
+        }
+        return $arguments;
+    }
+}

+ 3 - 137
lib/Predis/Commands/Processors/KeyPrefixProcessor.php

@@ -2,142 +2,13 @@
 
 namespace Predis\Commands\Processors;
 
-use Predis\ClientException;
 use Predis\Commands\ICommand;
-use Predis\Profiles\IServerProfile;
 
 class KeyPrefixProcessor implements ICommandProcessor {
     private $_prefix;
-    private $_strategies;
 
-    public function __construct($prefix, IServerProfile $profile = null) {
-        if (isset($profile)) {
-            $this->checkProfile($profile);
-        }
-        $this->_prefix = $prefix;
-        $this->_strategies = $this->getPrefixStrategies();
-    }
-
-    protected function checkProfile(IServerProfile $profile) {
-        if (!in_array($profile, $this->getSupportedProfiles())) {
-            throw new ClientException("Unsupported profile: $profile");
-        }
-    }
-
-    protected function getSupportedProfiles() {
-        return array('1.2', '2.0', '2.2');
-    }
-
-    protected function getPrefixStrategies() {
-        $skipLast = function(&$arguments, $prefix) {
-            $length = count($arguments);
-            for ($i = 0; $i < $length - 1; $i++) {
-                $arguments[$i] = "$prefix{$arguments[$i]}";
-            }
-        };
-
-        $interleavedKeys = function(&$arguments, $prefix) {
-            $length = count($arguments);
-            for ($i = 0; $i < $length; $i += 2) {
-                $arguments[$i] = "$prefix{$arguments[$i]}";
-            }
-        };
-
-        $zunionstore = function(&$arguments, $prefix) {
-            $arguments[0] = "$prefix{$arguments[0]}";
-            $length = ((int) $arguments[1]) + 2;
-            for ($i = 2; $i < $length; $i++) {
-                $arguments[$i] = "$prefix{$arguments[$i]}";
-            }
-        };
-
-        $sort = function(&$arguments, $prefix) {
-            $arguments[0] = "$prefix{$arguments[0]}";
-            if (count($arguments) === 1) {
-                return;
-            }
-            foreach ($arguments[1] as $modifier => &$value) {
-                switch (strtoupper($modifier)) {
-                    case 'BY':
-                    case 'STORE':
-                        $value = "$prefix$value";
-                        break;
-                    case 'GET':
-                        if (is_array($value)) {
-                            foreach ($value as &$getItem) {
-                                $getItem = "$prefix$getItem";
-                            }
-                        }
-                        else {
-                            $value = "$prefix$value";
-                        }
-                        break;
-                }
-            }
-        };
-
-        $debug = function(&$arguments, $prefix) {
-            if (count($arguments) === 3 && strtoupper($arguments[1]) == 'OBJECT') {
-                $arguments[2] = "$prefix{$arguments[2]}";
-            }
-        };
-
-        $cmdSingleKey = array(
-            'type', 'exists', 'move', 'expire', 'persist', 'sort', 'expireat', 'ttl', 'append',
-            'getrange', 'setnx', 'decr', 'getset', 'setrange', 'decrby', 'incr', 'set', 'strlen',
-            'get', 'incrby', 'setbit', 'getbit', 'setex', 'hdel', 'hgetall', 'hlen', 'hset',
-            'hexists', 'hincrby', 'hmget', 'hsetnx', 'hget', 'hkeys', 'hmset', 'hvals', 'lindex', 
-            'linsert', 'llen', 'lpop', 'lpush', 'lpushx', 'rpushx', 'lrange', 'lrem', 'lset',
-            'ltrim', 'rpop', 'rpush', 'rpushx', 'sadd', 'scard', 'sismember', 'smembers', 'spop', 
-            'srandmember', 'srem', 'zadd', 'zcard', 'zcount', 'zincrby', 'zrange', 'zrangebyscore', 
-            'zrank', 'zrem', 'zremrangebyrank', 'zremrangebyscore', 'zrevrange', 'zrevrangebyscore', 
-            'zrevrank', 'zscore', 'publish', 'keys',
-        );
-        $cmdMultiKeys = array(
-            'del', 'rename', 'renamenx', 'mget', 'rpoplpush', 'sdiff', 'sdiffstore', 'sinter', 
-            'sinterstore', 'sunion', 'sunionstore', 'subscribe', 'punsubscribe', 'subscribe', 
-            'unsubscribe', 'watch', 
-        );
-
-        return array_merge(
-            array_fill_keys($cmdSingleKey, $this->getSingleKeyStrategy()),
-            array_fill_keys($cmdMultiKeys, $this->getMultipleKeysStrategy()),
-            array(
-                'blpop' => $skipLast, 'brpop' => $skipLast, 'brpoplpush' => $skipLast, 'smove' => $skipLast,
-                'mset' => $interleavedKeys, 'msetnx' => $interleavedKeys,
-                'zinterstore' => $zunionstore, 'zunionstore' => $zunionstore,
-                'sort' => $sort, 'debug' => $debug
-            )
-        );
-    }
-
-    public function setPrefixStrategy($command, $strategy) {
-        if (!is_callable($callable)) {
-            throw new \InvalidArgumentException(
-                'The command preprocessor strategy must be a callable object'
-            );
-        }
-        $this->_strategies[$command] = $strategy;
-    }
-
-    public function getSingleKeyStrategy() {
-        return function(&$arguments, $prefix) {
-            $arguments[0] = "$prefix{$arguments[0]}";
-        };
-    }
-
-    public function getMultipleKeysStrategy() {
-        return function(&$arguments, $prefix) {
-            foreach ($arguments as &$key) {
-                $key = "$prefix$key";
-            }
-        };
-    }
-
-    public function getPrefixStrategy($command) {
-        if (isset($this->_strategies[$command])) {
-            return $this->_strategies[$command];
-        }
+    public function __construct($prefix) {
+        $this->setPrefix($prefix);
     }
 
     public function setPrefix($prefix) {
@@ -149,11 +20,6 @@ class KeyPrefixProcessor implements ICommandProcessor {
     }
 
     public function process(ICommand $command) {
-        $method = strtolower($command->getId());
-        if (isset($this->_strategies[$method])) {
-            $arguments = $command->getArguments();
-            $this->_strategies[$method]($arguments, $this->_prefix);
-            $command->setArguments($arguments);
-        }
+        $command->prefixKeys($this->_prefix);
     }
 }

+ 4 - 0
lib/Predis/Commands/PubSubSubscribe.php

@@ -13,6 +13,10 @@ class PubSubSubscribe extends Command {
         return Helpers::filterArrayArguments($arguments);
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 1 - 9
lib/Predis/Commands/PubSubSubscribeByPattern.php

@@ -4,16 +4,8 @@ namespace Predis\Commands;
 
 use Predis\Helpers;
 
-class PubSubSubscribeByPattern extends Command {
+class PubSubSubscribeByPattern extends PubSubSubscribe {
     public function getId() {
         return 'PSUBSCRIBE';
     }
-
-    public function filterArguments(Array $arguments) {
-        return Helpers::filterArrayArguments($arguments);
-    }
-
-    protected function canBeHashed() {
-        return false;
-    }
 }

+ 4 - 0
lib/Predis/Commands/PubSubUnsubscribe.php

@@ -7,6 +7,10 @@ class PubSubUnsubscribe extends Command {
         return 'UNSUBSCRIBE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 1 - 5
lib/Predis/Commands/PubSubUnsubscribeByPattern.php

@@ -2,12 +2,8 @@
 
 namespace Predis\Commands;
 
-class PubSubUnsubscribeByPattern extends Command {
+class PubSubUnsubscribeByPattern extends PubSubUnsubscribe {
     public function getId() {
         return 'PUNSUBSCRIBE';
     }
-
-    protected function canBeHashed() {
-        return false;
-    }
 }

+ 4 - 0
lib/Predis/Commands/ServerBackgroundRewriteAOF.php

@@ -7,6 +7,10 @@ class ServerBackgroundRewriteAOF extends Command {
         return 'BGREWRITEAOF';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerBackgroundSave.php

@@ -7,6 +7,10 @@ class ServerBackgroundSave extends Command {
         return 'BGSAVE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerClient.php

@@ -7,6 +7,10 @@ class ServerClient extends Command {
         return 'CLIENT';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerConfig.php

@@ -7,6 +7,10 @@ class ServerConfig extends Command {
         return 'CONFIG';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerDatabaseSize.php

@@ -7,6 +7,10 @@ class ServerDatabaseSize extends Command {
         return 'DBSIZE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerFlushAll.php

@@ -7,6 +7,10 @@ class ServerFlushAll extends Command {
         return 'FLUSHALL';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerFlushDatabase.php

@@ -7,6 +7,10 @@ class ServerFlushDatabase extends Command {
         return 'FLUSHDB';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerInfo.php

@@ -7,6 +7,10 @@ class ServerInfo extends Command {
         return 'INFO';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerLastSave.php

@@ -7,6 +7,10 @@ class ServerLastSave extends Command {
         return 'LASTSAVE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerMonitor.php

@@ -7,6 +7,10 @@ class ServerMonitor extends Command {
         return 'MONITOR';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerObject.php

@@ -9,6 +9,10 @@ class ServerObject extends Command {
         return 'OBJECT';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerSave.php

@@ -7,6 +7,10 @@ class ServerSave extends Command {
         return 'SAVE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerShutdown.php

@@ -7,6 +7,10 @@ class ServerShutdown extends Command {
         return 'SHUTDOWN';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/ServerSlaveOf.php

@@ -14,6 +14,10 @@ class ServerSlaveOf extends Command {
         return $arguments;
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/SetDifference.php

@@ -6,4 +6,8 @@ class SetDifference extends SetIntersection {
     public function getId() {
         return 'SDIFF';
     }
+
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
 }

+ 4 - 0
lib/Predis/Commands/SetIntersection.php

@@ -13,6 +13,10 @@ class SetIntersection extends Command {
         return Helpers::filterArrayArguments($arguments);
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys($this->getArguments());
     }

+ 4 - 0
lib/Predis/Commands/SetIntersectionStore.php

@@ -14,6 +14,10 @@ class SetIntersectionStore extends Command {
         return $arguments;
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys($this->getArguments());
     }

+ 4 - 0
lib/Predis/Commands/SetMove.php

@@ -7,6 +7,10 @@ class SetMove extends Command {
         return 'SMOVE';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::skipLastArgument($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/StringGetMultiple.php

@@ -13,6 +13,10 @@ class StringGetMultiple extends Command {
         return Helpers::filterArrayArguments($arguments);
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return $this->checkSameHashForKeys($this->getArguments());
     }

+ 8 - 0
lib/Predis/Commands/StringSetMultiple.php

@@ -20,6 +20,14 @@ class StringSetMultiple extends Command {
         return $arguments;
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        $length = count($arguments);
+        for ($i = 0; $i < $length; $i += 2) {
+            $arguments[$i] = "$prefix{$arguments[$i]}";
+        }
+        return $arguments;
+    }
+
     protected function canBeHashed() {
         $args = $this->getArguments();
         $keys = array();

+ 4 - 0
lib/Predis/Commands/TransactionDiscard.php

@@ -7,6 +7,10 @@ class TransactionDiscard extends Command {
         return 'DISCARD';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/TransactionExec.php

@@ -7,6 +7,10 @@ class TransactionExec extends Command {
         return 'EXEC';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/TransactionMulti.php

@@ -7,6 +7,10 @@ class TransactionMulti extends Command {
         return 'MULTI';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/TransactionUnwatch.php

@@ -7,6 +7,10 @@ class TransactionUnwatch extends Command {
         return 'UNWATCH';
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        /* NOOP */
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 4 - 0
lib/Predis/Commands/TransactionWatch.php

@@ -14,6 +14,10 @@ class TransactionWatch extends Command {
         return $arguments;
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        return PrefixHelpers::multipleKeys($arguments, $prefix);
+    }
+
     protected function canBeHashed() {
         return false;
     }

+ 9 - 0
lib/Predis/Commands/ZSetUnionStore.php

@@ -38,6 +38,15 @@ class ZSetUnionStore extends Command {
         return $finalizedOpts;
     }
 
+    protected function onPrefixKeys(Array $arguments, $prefix) {
+        $arguments[0] = "$prefix{$arguments[0]}";
+        $length = ((int) $arguments[1]) + 2;
+        for ($i = 2; $i < $length; $i++) {
+            $arguments[$i] = "$prefix{$arguments[$i]}";
+        }
+        return $arguments;
+    }
+
     protected function canBeHashed() {
         $args = $this->getArguments();
         return $this->checkSameHashForKeys(