You are here

public function Redis_Client_Predis::getClient in Redis 7.3

Same name and namespace in other branches
  1. 7 lib/Redis/Client/Predis.php \Redis_Client_Predis::getClient()
  2. 7.2 lib/Redis/Client/Predis.php \Redis_Client_Predis::getClient()

Get the connected client instance.

Parameters

array $options: Options from the server pool configuration that may contain:

  • host
  • port
  • database
  • password
  • socket

Return value

mixed Real client depends from the library behind.

Overrides Redis_Client_FactoryInterface::getClient

File

lib/Redis/Client/Predis.php, line 112

Class

Redis_Client_Predis
Predis client specific implementation.

Code

public function getClient($options = array()) {
  self::setPredisAutoload();
  if (!empty($options['socket'])) {
    $options['scheme'] = 'unix';
    $options['path'] = $options['socket'];
  }
  foreach ($options as $key => $value) {
    if (!isset($value)) {
      unset($options[$key]);
    }
  }

  // I'm not sure why but the error handler is driven crazy if timezone
  // is not set at this point.
  // Hopefully Drupal will restore the right one this once the current
  // account has logged in.
  date_default_timezone_set(@date_default_timezone_get());
  $client = new \Predis\Client($options);
  if (isset($options['base']) && 0 !== $options['base']) {
    $client
      ->select((int) $options['base']);
  }
  return $client;
}