You are here

public function Redis_Client_PhpRedis::getClient in Redis 7.3

Same name and namespace in other branches
  1. 7 lib/Redis/Client/PhpRedis.php \Redis_Client_PhpRedis::getClient()
  2. 7.2 lib/Redis/Client/PhpRedis.php \Redis_Client_PhpRedis::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/PhpRedis.php, line 8

Class

Redis_Client_PhpRedis
PhpRedis client specific implementation.

Code

public function getClient($options = array()) {
  $client = new Redis();
  if (!empty($options['socket'])) {
    $client
      ->connect($options['socket']);
  }
  else {
    $client
      ->connect($options['host'], $options['port']);
  }
  if (isset($options['password'])) {
    $client
      ->auth($options['password']);
  }
  if (isset($options['base'])) {
    $client
      ->select($options['base']);
  }

  // Do not allow PhpRedis serialize itself data, we are going to do it
  // ourself. This will ensure less memory footprint on Redis size when
  // we will attempt to store small values.
  $client
    ->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
  return $client;
}