diff --git a/lib/Predis/Commands/Command.php b/lib/Predis/Commands/Command.php index f7a24cb7..5697dae7 100644 --- a/lib/Predis/Commands/Command.php +++ b/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]); } diff --git a/lib/Predis/Commands/ConnectionAuth.php b/lib/Predis/Commands/ConnectionAuth.php index 181a2be5..d2fd0dcb 100644 --- a/lib/Predis/Commands/ConnectionAuth.php +++ b/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; } diff --git a/lib/Predis/Commands/ConnectionEcho.php b/lib/Predis/Commands/ConnectionEcho.php index fca78bd6..49cc920b 100644 --- a/lib/Predis/Commands/ConnectionEcho.php +++ b/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; } diff --git a/lib/Predis/Commands/ConnectionPing.php b/lib/Predis/Commands/ConnectionPing.php index 2ccb12db..28399dc1 100644 --- a/lib/Predis/Commands/ConnectionPing.php +++ b/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; } diff --git a/lib/Predis/Commands/ConnectionQuit.php b/lib/Predis/Commands/ConnectionQuit.php index b7d58f74..e3ef0e96 100644 --- a/lib/Predis/Commands/ConnectionQuit.php +++ b/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; } diff --git a/lib/Predis/Commands/ConnectionSelect.php b/lib/Predis/Commands/ConnectionSelect.php index 254cb3c8..1caf143c 100644 --- a/lib/Predis/Commands/ConnectionSelect.php +++ b/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; } diff --git a/lib/Predis/Commands/ICommand.php b/lib/Predis/Commands/ICommand.php index 660b58ee..f1a43a2a 100644 --- a/lib/Predis/Commands/ICommand.php +++ b/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); } diff --git a/lib/Predis/Commands/KeyDelete.php b/lib/Predis/Commands/KeyDelete.php index f5b28fa1..12246291 100644 --- a/lib/Predis/Commands/KeyDelete.php +++ b/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) { diff --git a/lib/Predis/Commands/KeyRename.php b/lib/Predis/Commands/KeyRename.php index c866972d..103b4f7b 100644 --- a/lib/Predis/Commands/KeyRename.php +++ b/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; } diff --git a/lib/Predis/Commands/KeyRenamePreserve.php b/lib/Predis/Commands/KeyRenamePreserve.php index 4421c13a..337317bb 100644 --- a/lib/Predis/Commands/KeyRenamePreserve.php +++ b/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; } diff --git a/lib/Predis/Commands/KeySort.php b/lib/Predis/Commands/KeySort.php index bef3430d..b5e65d9a 100644 --- a/lib/Predis/Commands/KeySort.php +++ b/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; + } } diff --git a/lib/Predis/Commands/ListPopFirstBlocking.php b/lib/Predis/Commands/ListPopFirstBlocking.php index 31c9b9ce..46f83cad 100644 --- a/lib/Predis/Commands/ListPopFirstBlocking.php +++ b/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) diff --git a/lib/Predis/Commands/ListPopLastPushHead.php b/lib/Predis/Commands/ListPopLastPushHead.php index 390d7213..13d9c112 100644 --- a/lib/Predis/Commands/ListPopLastPushHead.php +++ b/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()); } diff --git a/lib/Predis/Commands/ListPopLastPushHeadBlocking.php b/lib/Predis/Commands/ListPopLastPushHeadBlocking.php index 0e0088fa..87608c66 100644 --- a/lib/Predis/Commands/ListPopLastPushHeadBlocking.php +++ b/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) diff --git a/lib/Predis/Commands/PrefixHelpers.php b/lib/Predis/Commands/PrefixHelpers.php new file mode 100644 index 00000000..8e682c81 --- /dev/null +++ b/lib/Predis/Commands/PrefixHelpers.php @@ -0,0 +1,20 @@ +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); } } diff --git a/lib/Predis/Commands/PubSubSubscribe.php b/lib/Predis/Commands/PubSubSubscribe.php index e621cde8..e1abc479 100644 --- a/lib/Predis/Commands/PubSubSubscribe.php +++ b/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; } diff --git a/lib/Predis/Commands/PubSubSubscribeByPattern.php b/lib/Predis/Commands/PubSubSubscribeByPattern.php index ea733226..1af67b1d 100644 --- a/lib/Predis/Commands/PubSubSubscribeByPattern.php +++ b/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; - } } diff --git a/lib/Predis/Commands/PubSubUnsubscribe.php b/lib/Predis/Commands/PubSubUnsubscribe.php index fd861e61..862ee9d4 100644 --- a/lib/Predis/Commands/PubSubUnsubscribe.php +++ b/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; } diff --git a/lib/Predis/Commands/PubSubUnsubscribeByPattern.php b/lib/Predis/Commands/PubSubUnsubscribeByPattern.php index eead9b63..36e6e28e 100644 --- a/lib/Predis/Commands/PubSubUnsubscribeByPattern.php +++ b/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; - } } diff --git a/lib/Predis/Commands/ServerBackgroundRewriteAOF.php b/lib/Predis/Commands/ServerBackgroundRewriteAOF.php index 2ea0111d..19477c2a 100644 --- a/lib/Predis/Commands/ServerBackgroundRewriteAOF.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerBackgroundSave.php b/lib/Predis/Commands/ServerBackgroundSave.php index ebf5d13f..85f02e26 100644 --- a/lib/Predis/Commands/ServerBackgroundSave.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerClient.php b/lib/Predis/Commands/ServerClient.php index 1642895a..90d32001 100644 --- a/lib/Predis/Commands/ServerClient.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerConfig.php b/lib/Predis/Commands/ServerConfig.php index f0a3bda9..1f78e9b8 100644 --- a/lib/Predis/Commands/ServerConfig.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerDatabaseSize.php b/lib/Predis/Commands/ServerDatabaseSize.php index 72d2bdf0..8e8e64b2 100644 --- a/lib/Predis/Commands/ServerDatabaseSize.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerFlushAll.php b/lib/Predis/Commands/ServerFlushAll.php index 6bd02341..be695a5f 100644 --- a/lib/Predis/Commands/ServerFlushAll.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerFlushDatabase.php b/lib/Predis/Commands/ServerFlushDatabase.php index 57fa6827..2443990f 100644 --- a/lib/Predis/Commands/ServerFlushDatabase.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerInfo.php b/lib/Predis/Commands/ServerInfo.php index eed1f662..4d1f3459 100644 --- a/lib/Predis/Commands/ServerInfo.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerLastSave.php b/lib/Predis/Commands/ServerLastSave.php index 34dbbc18..3f430c54 100644 --- a/lib/Predis/Commands/ServerLastSave.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerMonitor.php b/lib/Predis/Commands/ServerMonitor.php index 2f06b408..55637e8f 100644 --- a/lib/Predis/Commands/ServerMonitor.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerObject.php b/lib/Predis/Commands/ServerObject.php index 119833dc..3081e366 100644 --- a/lib/Predis/Commands/ServerObject.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerSave.php b/lib/Predis/Commands/ServerSave.php index cb73d447..e90a94ba 100644 --- a/lib/Predis/Commands/ServerSave.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerShutdown.php b/lib/Predis/Commands/ServerShutdown.php index 5fd265fa..22026332 100644 --- a/lib/Predis/Commands/ServerShutdown.php +++ b/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; } diff --git a/lib/Predis/Commands/ServerSlaveOf.php b/lib/Predis/Commands/ServerSlaveOf.php index 649b2c98..53628810 100644 --- a/lib/Predis/Commands/ServerSlaveOf.php +++ b/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; } diff --git a/lib/Predis/Commands/SetDifference.php b/lib/Predis/Commands/SetDifference.php index e509d61c..b4aeed4d 100644 --- a/lib/Predis/Commands/SetDifference.php +++ b/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); + } } diff --git a/lib/Predis/Commands/SetIntersection.php b/lib/Predis/Commands/SetIntersection.php index afc37e5a..1cccf9a4 100644 --- a/lib/Predis/Commands/SetIntersection.php +++ b/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()); } diff --git a/lib/Predis/Commands/SetIntersectionStore.php b/lib/Predis/Commands/SetIntersectionStore.php index af2417fc..a761dbee 100644 --- a/lib/Predis/Commands/SetIntersectionStore.php +++ b/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()); } diff --git a/lib/Predis/Commands/SetMove.php b/lib/Predis/Commands/SetMove.php index 0d5de8e3..146a86fa 100644 --- a/lib/Predis/Commands/SetMove.php +++ b/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; } diff --git a/lib/Predis/Commands/StringGetMultiple.php b/lib/Predis/Commands/StringGetMultiple.php index ba94d14b..dbac7da4 100644 --- a/lib/Predis/Commands/StringGetMultiple.php +++ b/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()); } diff --git a/lib/Predis/Commands/StringSetMultiple.php b/lib/Predis/Commands/StringSetMultiple.php index 050e393a..54163238 100644 --- a/lib/Predis/Commands/StringSetMultiple.php +++ b/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(); diff --git a/lib/Predis/Commands/TransactionDiscard.php b/lib/Predis/Commands/TransactionDiscard.php index f34407ec..47465149 100644 --- a/lib/Predis/Commands/TransactionDiscard.php +++ b/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; } diff --git a/lib/Predis/Commands/TransactionExec.php b/lib/Predis/Commands/TransactionExec.php index e053c7a3..a9fbb0e7 100644 --- a/lib/Predis/Commands/TransactionExec.php +++ b/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; } diff --git a/lib/Predis/Commands/TransactionMulti.php b/lib/Predis/Commands/TransactionMulti.php index a0a5188f..c889b084 100644 --- a/lib/Predis/Commands/TransactionMulti.php +++ b/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; } diff --git a/lib/Predis/Commands/TransactionUnwatch.php b/lib/Predis/Commands/TransactionUnwatch.php index 17afc8f1..f031d899 100644 --- a/lib/Predis/Commands/TransactionUnwatch.php +++ b/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; } diff --git a/lib/Predis/Commands/TransactionWatch.php b/lib/Predis/Commands/TransactionWatch.php index 7547b25d..8adc8688 100644 --- a/lib/Predis/Commands/TransactionWatch.php +++ b/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; } diff --git a/lib/Predis/Commands/ZSetUnionStore.php b/lib/Predis/Commands/ZSetUnionStore.php index ff81680b..7797ff9f 100644 --- a/lib/Predis/Commands/ZSetUnionStore.php +++ b/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(