Client.php in Redis 7        
                          
                  
                        
  
  
  
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_BASE = NULL;
  
  protected static $_clientInterface;
  
  protected static $_client;
  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() {
    if (!isset(self::$_clientInterface)) {
      global $conf;
      if (isset($conf['redis_client_interface']) && class_exists($conf['redis_client_interface'])) {
        self::$_clientInterface = new $conf['redis_client_interface']();
      }
      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_cache_host']) ? $conf['redis_client_host'] : self::REDIS_DEFAULT_HOST, isset($conf['redis_cache_port']) ? $conf['redis_client_port'] : self::REDIS_DEFAULT_PORT, isset($conf['redis_cache_base']) ? $conf['redis_client_base'] : self::REDIS_DEFAULT_BASE);
    }
    return self::$_client;
  }
}
 
Classes
        
  
  
      
      
         
      
                  | Name   | Description | 
    
    
          
                  | Redis_Client | Common code and client singleton, for all Redis clients. |