diff --git a/src/Factory/RedisFactory.php b/src/Factory/RedisFactory.php index e9a6c42..68f61e6 100644 --- a/src/Factory/RedisFactory.php +++ b/src/Factory/RedisFactory.php @@ -39,16 +39,16 @@ public function getAdapter(array $config) throw new ConnectException(sprintf('Could not connect to Redis database on "%s:%s".', $config['host'], $config['port'])); } } else { + if (false === $client->connect($dsn->getFirstHost(), $dsn->getFirstPort())) { + throw new ConnectException(sprintf('Could not connect to Redis database on "%s:%s".', $dsn->getFirstHost(), $dsn->getFirstPort())); + } + if (!empty($dsn->getPassword())) { if (false === $client->auth($dsn->getPassword())) { throw new ConnectException('Could not connect authenticate connection to Redis database.'); } } - if (false === $client->connect($dsn->getFirstHost(), $dsn->getFirstPort())) { - throw new ConnectException(sprintf('Could not connect to Redis database on "%s:%s".', $dsn->getFirstHost(), $dsn->getFirstPort())); - } - if ($dsn->getDatabase() !== null) { if (false === $client->select($dsn->getDatabase())) { throw new ConnectException(sprintf('Could not select Redis database with index "%s".', $dsn->getDatabase()));