You are here

public function PhpRedis::getClient in Redis 8

Get the connected client instance.

Return value

mixed Real client depends from the library behind.

Overrides ClientInterface::getClient

File

src/Client/PhpRedis.php, line 17

Class

PhpRedis
PhpRedis client specific implementation.

Namespace

Drupal\redis\Client

Code

public function getClient($host = NULL, $port = NULL, $base = NULL, $password = NULL, $replicationHosts = [], $persistent = FALSE) {
  $client = new \Redis();

  // Sentinel mode, get the real master.
  if (is_array($host)) {
    $ip_host = $this
      ->askForMaster($client, $host, $password);
    if (is_array($ip_host)) {
      list($host, $port) = $ip_host;
    }
  }
  if ($persistent) {
    $client
      ->pconnect($host, $port);
  }
  else {
    $client
      ->connect($host, $port);
  }
  if (isset($password)) {
    $client
      ->auth($password);
  }
  if (isset($base)) {
    $client
      ->select($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;
}