Predis.php in Redis 8
File
src/Client/Predis.php
View source
<?php
namespace Drupal\redis\Client;
use Drupal\redis\ClientInterface;
use Predis\Client;
class Predis implements ClientInterface {
public function getClient($host = NULL, $port = NULL, $base = NULL, $password = NULL, $replicationHosts = [], $persistent = FALSE) {
$connectionInfo = [
'password' => $password,
'host' => $host,
'port' => $port,
'database' => $base,
'persistent' => $persistent,
];
foreach ($connectionInfo as $key => $value) {
if (!isset($value)) {
unset($connectionInfo[$key]);
}
}
date_default_timezone_set(@date_default_timezone_get());
if (!empty($replicationHosts)) {
$parameters = [];
foreach ($replicationHosts as $replicationHost) {
$param = 'tcp://' . $replicationHost['host'] . ':' . $replicationHost['port'] . '?persistent=' . ($persistent ? 'true' : 'false');
if ($replicationHost['role'] === 'primary') {
$param .= '&alias=master';
}
$parameters[] = $param;
}
$options = [
'replication' => true,
];
$client = new Client($parameters, $options);
}
else {
$client = new Client($connectionInfo);
}
return $client;
}
public function getName() {
return 'Predis';
}
}
Classes
Name |
Description |
Predis |
Predis client specific implementation. |