Skip to content

Commit

Permalink
Add 'username' auth option to Redis driver
Browse files Browse the repository at this point in the history
  • Loading branch information
okiedork committed May 28, 2022
1 parent 9f48e6d commit 31379e9
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 31379e9

Please sign in to comment.