You are here

protected function RedisProfilerStorage::getRedis in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Profiler/RedisProfilerStorage.php \Symfony\Component\HttpKernel\Profiler\RedisProfilerStorage::getRedis()

Internal convenience method that returns the instance of Redis.

Return value

\Redis

Throws

\RuntimeException

3 calls to RedisProfilerStorage::getRedis()
RedisProfilerStorage::appendValue in vendor/symfony/http-kernel/Profiler/RedisProfilerStorage.php
Appends data to an existing item on the Redis server.
RedisProfilerStorage::getValue in vendor/symfony/http-kernel/Profiler/RedisProfilerStorage.php
Retrieves an item from the Redis server.
RedisProfilerStorage::setValue in vendor/symfony/http-kernel/Profiler/RedisProfilerStorage.php
Stores an item on the Redis server under the specified key.

File

vendor/symfony/http-kernel/Profiler/RedisProfilerStorage.php, line 207

Class

RedisProfilerStorage
RedisProfilerStorage stores profiling information in Redis.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

protected function getRedis() {
  if (null === $this->redis) {
    $data = parse_url($this->dsn);
    if (false === $data || !isset($data['scheme']) || $data['scheme'] !== 'redis' || !isset($data['host']) || !isset($data['port'])) {
      throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn "%s". The minimal expected format is "redis://[host]:port".', $this->dsn));
    }
    if (!extension_loaded('redis')) {
      throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
    }
    $redis = new \Redis();
    $redis
      ->connect($data['host'], $data['port']);
    if (isset($data['path'])) {
      $redis
        ->select(substr($data['path'], 1));
    }
    if (isset($data['pass'])) {
      $redis
        ->auth($data['pass']);
    }
    $redis
      ->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
    $this->redis = $redis;
  }
  return $this->redis;
}