mirror of
https://github.com/predis/predis.git
synced 2026-09-17 13:57:33 +00:00
Added the new abstract class 'RedisServerCompatibility'. Its subclassess will be used to define a set compatibility profiles for each version of the Redis server. The only drawback is that the selected compatibility profile will be shared among multiple connections when using client-side sharding.
This commit is contained in:
@@ -789,6 +789,56 @@ class ConnectionCluster implements IConnection {
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
abstract class RedisServerCompatibility {
|
||||
private $_registeredCommands;
|
||||
|
||||
public function __construct() {
|
||||
$this->_registeredCommands = $this->getSupportedCommands();
|
||||
}
|
||||
|
||||
public abstract function getVersion();
|
||||
|
||||
protected abstract function getSupportedCommands();
|
||||
|
||||
public function createCommandInstance($method, $arguments) {
|
||||
$commandClass = $this->_registeredCommands[$method];
|
||||
|
||||
if ($commandClass === null) {
|
||||
throw new ClientException("'$method' is not a registered Redis command");
|
||||
}
|
||||
|
||||
$command = new $commandClass();
|
||||
$command->setArgumentsArray($arguments);
|
||||
return $command;
|
||||
}
|
||||
|
||||
|
||||
public function registerCommands(Array $commands) {
|
||||
foreach ($commands as $command => $aliases) {
|
||||
$this->registerCommand($command, $aliases);
|
||||
}
|
||||
}
|
||||
|
||||
public function registerCommand($command, $aliases) {
|
||||
$commandReflection = new \ReflectionClass($command);
|
||||
|
||||
if (!$commandReflection->isSubclassOf('\Predis\Command')) {
|
||||
throw new ClientException("Cannot register '$command' as it is not a valid Redis command");
|
||||
}
|
||||
|
||||
if (is_array($aliases)) {
|
||||
foreach ($aliases as $alias) {
|
||||
$this->_registeredCommands[$alias] = $command;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_registeredCommands[$aliases] = $command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
namespace Predis\Utilities;
|
||||
|
||||
class HashRing {
|
||||
|
||||
Reference in New Issue
Block a user