Client.php in Redis 7.2
File
lib/Redis/Client.php
View source
<?php
if (!interface_exists('Redis_Client_Interface')) {
require_once dirname(__FILE__) . '/Client/Interface.php';
}
class Redis_Client {
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 REDIS_IMPL_CACHE = 'Redis_Cache_';
const REDIS_IMPL_LOCK = 'Redis_Lock_Backend_';
const REDIS_IMPL_QUEUE = 'Redis_Queue_';
const REDIS_IMPL_SESSION = 'Redis_Session_Backend_';
const REDIS_IMPL_PATH = 'Redis_Path_';
const REDIS_IMPL_CLIENT = 'Redis_Client_';
protected static $_clientInterface;
protected static $_client;
protected static $globalPrefix;
public static function hasClient() {
return isset(self::$_client);
}
public static function setClient(Redis_Client_Interface $interface) {
if (isset(self::$_client)) {
throw new Exception("Once Redis client is connected, you cannot change client proxy instance.");
}
self::$_clientInterface = $interface;
}
public static function getClientInterface() {
global $conf;
if (!isset(self::$_clientInterface)) {
if (!empty($conf['redis_client_interface'])) {
$className = self::getClass(self::REDIS_IMPL_CLIENT, $conf['redis_client_interface']);
self::$_clientInterface = new $className();
}
else {
if (class_exists('Predis\\Client')) {
$className = self::getClass(self::REDIS_IMPL_CLIENT, 'Predis');
self::$_clientInterface = new $className();
}
else {
if (class_exists('Redis')) {
$className = self::getClass(self::REDIS_IMPL_CLIENT, 'PhpRedis');
self::$_clientInterface = new $className();
}
else {
if (!isset(self::$_clientInterface)) {
throw new Exception("No client interface set.");
}
}
}
}
}
return self::$_clientInterface;
}
public static function getClientName() {
return self::getClientInterface()
->getName();
}
public static function getClient() {
if (!isset(self::$_client)) {
global $conf;
self::$_client = self::getClientInterface()
->getClient(isset($conf['redis_client_host']) ? $conf['redis_client_host'] : self::REDIS_DEFAULT_HOST, isset($conf['redis_client_port']) ? $conf['redis_client_port'] : self::REDIS_DEFAULT_PORT, isset($conf['redis_client_base']) ? $conf['redis_client_base'] : self::REDIS_DEFAULT_BASE, isset($conf['redis_client_password']) ? $conf['redis_client_password'] : self::REDIS_DEFAULT_PASSWORD, isset($conf['redis_client_socket']) ? $conf['redis_client_socket'] : self::REDIS_DEFAULT_SOCKET);
}
return self::$_client;
}
public static function getClass($system, $clientName = NULL) {
$className = $system . (isset($clientName) ? $clientName : self::getClientName());
if (!class_exists($className)) {
throw new Exception($className . " does not exists");
}
return $className;
}
public static function reset() {
self::$globalPrefix = null;
self::$_clientInterface = null;
self::$_client = null;
}
}
Classes
Name |
Description |
Redis_Client |
Common code and client singleton, for all Redis clients. |