Manager.php in Redis 7.3
File
lib/Redis/Client/Manager.php
View source
<?php
class Redis_Client_Manager {
const REDIS_DEFAULT_HOST = '127.0.0.1';
const REDIS_DEFAULT_PORT = 6379;
const REDIS_DEFAULT_SOCKET = null;
const REDIS_DEFAULT_BASE = null;
const REDIS_DEFAULT_PASSWORD = null;
const REALM_DEFAULT = 'default';
private $interfaceName;
private $serverList = array();
private $clients = array();
private $factory;
public function __construct(Redis_Client_FactoryInterface $factory, $serverList = array()) {
$this->factory = $factory;
$this->serverList = $serverList;
}
public function getClient($realm = self::REALM_DEFAULT, $allowDefault = true) {
if (!isset($this->clients[$realm])) {
$client = $this
->createClient($realm);
if (false === $client) {
if (self::REALM_DEFAULT !== $realm && $allowDefault) {
$this->clients[$realm] = $this
->getClient(self::REALM_DEFAULT);
}
else {
throw new InvalidArgumentException(sprintf("Could not find client for realm '%s'", $realm));
}
}
else {
$this->clients[$realm] = $client;
}
}
return $this->clients[$realm];
}
private function buildOptions($realm) {
$info = null;
if (isset($this->serverList[$realm])) {
$info = $this->serverList[$realm];
}
else {
return false;
}
$info += array(
'host' => self::REDIS_DEFAULT_HOST,
'port' => self::REDIS_DEFAULT_PORT,
'base' => self::REDIS_DEFAULT_BASE,
'password' => self::REDIS_DEFAULT_PASSWORD,
'socket' => self::REDIS_DEFAULT_SOCKET,
);
return array_filter($info);
}
private function createClient($realm) {
$info = $this
->buildOptions($realm);
if (false === $info) {
return false;
}
return $this->factory
->getClient($info);
}
}