-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: Option to add an username to the RedisBackend configuration #3347
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some kind of test would be great… Then again, I am not sure we even test the password functionality. 🙄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 by 👀
Two more things that would be great:
|
@@ -535,7 +543,8 @@ private function getRedisClient(): \Redis | |||
} | |||
} | |||
|
|||
if ($this->password !== '' && !$redis->auth($this->password)) { | |||
$credentials = array_values(array_filter([$this->username, $this->password])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to make this code a bit more readable – as not everyone is familiar with array_filter()
and the fact that $redis->auth()
accepts both a string or an array (see docs).
Also, I'd prefer strict comparisons over weak ones like `empty()'.
How about something like this?
if ($this->username !== '' && $this->password !== '') {
$result = $redis->auth([$this->username, $this->password]);
if ($result === false) {
throw new CacheException(sprintf('Redis authentication failed, using username "%s" and a %s bytes long password.', $this->username, strlen($this->password)), 1725607160);
}
} elseif ($this->password !== '') {
$result = $redis->auth($this->password);
if ($result === false) {
throw new CacheException(sprintf('Redis authentication failed, using a %s bytes long password.', strlen($this->password)), 1502366200);
}
} else {
$result = $redis->auth();
if ($result === false) {
throw new CacheException('Redis authentication with empty password failed.', 1725607324);
}
}
Thx for the feedback. I will re-open a merge request for flow 8.4 with the suggested changes this afternoon :). |
Thanks for taking care, I'm happy that we'll have that new feature! |
Redis has support for authentication which supplies an username+password combination. This PR extends the current RedisBackend so that an username can be supplied in addition to the password. The underlying library already the authentication, hence it simply needs to be configured and passed.