You are here

class Predis in Redis 8

Same name in this branch
  1. 8 src/Lock/Predis.php \Drupal\redis\Lock\Predis
  2. 8 src/Flood/Predis.php \Drupal\redis\Flood\Predis
  3. 8 src/Queue/Predis.php \Drupal\redis\Queue\Predis
  4. 8 src/Client/Predis.php \Drupal\redis\Client\Predis
  5. 8 src/Cache/Predis.php \Drupal\redis\Cache\Predis
  6. 8 src/PersistentLock/Predis.php \Drupal\redis\PersistentLock\Predis

Predis client specific implementation.

Hierarchy

Expanded class hierarchy of Predis

3 string references to 'Predis'
ClientFactory::getClientInterface in src/ClientFactory.php
Lazy instantiates client proxy depending on the actual configuration.
Predis::getName in src/Client/Predis.php
Get underlying library name used.
RedisCacheTagsChecksum::doInvalidateTags in src/Cache/RedisCacheTagsChecksum.php
Marks cache items with any of the specified tags as invalid.

File

src/Client/Predis.php, line 12

Namespace

Drupal\redis\Client
View source
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]);
      }
    }

    // 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());

    // If we are passed in an array of $replicationHosts, we should attempt a clustered client connection.
    if (!empty($replicationHosts)) {
      $parameters = [];
      foreach ($replicationHosts as $replicationHost) {
        $param = 'tcp://' . $replicationHost['host'] . ':' . $replicationHost['port'] . '?persistent=' . ($persistent ? 'true' : 'false');

        // Configure master.
        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';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Predis::getClient public function Get the connected client instance. Overrides ClientInterface::getClient
Predis::getName public function Get underlying library name used. Overrides ClientInterface::getName