You are here

public static function Redis_Client::getClientInterface in Redis 7.2

Same name and namespace in other branches
  1. 7 lib/Redis/Client.php \Redis_Client::getClientInterface()

Lazy instanciate client proxy depending on the actual configuration.

If you are using a lock, session or cache backend using one of the Redis client implementation, this will be overrided at early bootstrap phase and configuration will be ignored.

Return value

Redis_Client_Interface

File

lib/Redis/Client.php, line 112

Class

Redis_Client
Common code and client singleton, for all Redis clients.

Code

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')) {

        // Transparent and abitrary preference for Predis library.
        $className = self::getClass(self::REDIS_IMPL_CLIENT, 'Predis');
        self::$_clientInterface = new $className();
      }
      else {
        if (class_exists('Redis')) {

          // Fallback on PhpRedis if available.
          $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;
}