SncRedisBundle icon indicating copy to clipboard operation
SncRedisBundle copied to clipboard

Can't connect using username and password in a DSN

Open bruno-buiret opened this issue 3 years ago • 0 comments

Hello,

I've been trying to connect to a Redis server using a full DSN redis://username:password@host:port/database but there appears to be a problem detecting the username inside the PhpredisClientFactory class in the method createClient()

$username = $options['parameters']['username'] ?? null;
// Shouldn't this be $dsn->getUsername() ?? $options['parameters']['username'] ?? null; just like for the password?
$password = $dsn->getPassword() ?? $options['parameters']['password'] ?? null;
if ($username !== null && $password !== null) {
    $client->auth([$username, $password]);
} elseif ($password !== null) {
    $client->auth($password);
}

For now I've used environment variable processors (https://symfony.com/doc/current/configuration/env_var_processors.html#built-in-environment-variable-processors) to extract the username from the DSN and use the options.parameters.username property.

Thank you!

bruno-buiret avatar Jul 25 '22 17:07 bruno-buiret