/**
  * @dataProvider dsnValues
  *
  * @param string      $dsn
  * @param string      $host
  * @param int|null    $port
  * @param string|null $database
  * @param string|null $password
  * @param int|null    $weight
  * @param string|null $alias
  */
 public function testDsn($dsn, $host, $port = null, $database = null, $password = null, $weight = null, $alias = null)
 {
     $dsn = new RedisDsn($dsn);
     if (substr($host, -5) === '.sock') {
         $this->assertSame($host, $dsn->getSocket());
     } else {
         $this->assertSame($host, $dsn->getHost());
     }
     $this->assertSame($port, $dsn->getPort());
     $this->assertSame($database, $dsn->getDatabase());
     $this->assertSame($password, $dsn->getPassword());
     $this->assertSame($weight, $dsn->getWeight());
     $this->assertSame($alias, $dsn->getAlias());
 }
 /**
  * Loads a Redis config.
  *
  * @param string           $id
  * @param array            $config    A config configuration
  * @param ContainerBuilder $container A ContainerBuilder instance
  *
  * @throws \LogicException When Redis extension is not loaded
  *
  * @return Definition
  */
 protected function loadPhpredisDriver($id, array $config, ContainerBuilder $container)
 {
     // Check if the Redis extension is loaded
     if (!extension_loaded('redis')) {
         throw new \LogicException('Redis extension is not loaded');
     }
     $dsn = new RedisDsn($config['dsn']);
     $connectMethod = $config['connection']['persistent'] ? 'pconnect' : 'connect';
     $connectParameters = [];
     if (null !== $dsn->getSocket()) {
         $connectParameters[] = $dsn->getSocket();
         $connectParameters[] = null;
     } else {
         $connectParameters[] = $dsn->getHost();
         $connectParameters[] = $dsn->getPort();
     }
     $connectParameters[] = $config['connection']['timeout'];
     if ($config['connection']['persistent']) {
         $connectParameters[] = $id;
     }
     $client = new Definition($container->getParameter('tree_house_cache.phpredis_client.class'));
     $client->addMethodCall($connectMethod, $connectParameters);
     if ($config['prefix']) {
         $client->addMethodCall('setOption', [\Redis::OPT_PREFIX, $config['prefix']]);
     }
     if (null !== $dsn->getPassword()) {
         $client->addMethodCall('auth', [$dsn->getPassword()]);
     }
     if (null !== $dsn->getDatabase()) {
         $client->addMethodCall('select', [$dsn->getDatabase()]);
     }
     $container->setDefinition(sprintf('%s.cache', $id), $client);
     $driver = new Definition($container->getParameter('tree_house_cache.phpredis_driver.class'));
     $driver->addArgument($client);
     return $driver;
 }