Skip to content

Commit

Permalink
Merge pull request #413 from okiedork/feat/redis-auth-username
Browse files Browse the repository at this point in the history
Add 'username' auth option to Redis driver
  • Loading branch information
tedivm committed May 28, 2022
2 parents 9f48e6d + 31379e9 commit e6d5534
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Stash/Driver/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class Redis extends AbstractDriver
*
* The "database" option lets developers specific which specific database to use.
*
* The "password" option is used for clusters which required authentication.
* The "password" option is used for clusters which require authentication.
*
* The "username" option is used for authentication with a non-default user, for clusters which have ACL rules.
* If "username" isn't set, but "password" is set, the `default` user will be used for authentication.
*
* @param array $options
*/
Expand Down Expand Up @@ -121,9 +124,18 @@ protected function setOptions(array $options = array())
$redis->connect($server['server'], $port, $ttl);
}

// auth - just password
// authentication
if (isset($options['password'])) {
$redis->auth($options['password']);
if (isset($options['username'])) {
$redis->auth(
[
'user' => $options['username'],
'pass' => $options['password']
]
);
} else {
$redis->auth(['pass' => $options['password']]);
}
}

$this->redis = $redis;
Expand Down

0 comments on commit e6d5534

Please sign in to comment.