Skip to content
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

Added REDIS cache configuration property ("username") in cache config… #4569

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions framework/caching/CRedisCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* 'port'=>6379,
* 'database'=>0,
* 'options'=>STREAM_CLIENT_CONNECT,
* 'username' => 'default' // only for REDIS version 6.0 or later
marcovtwout marked this conversation as resolved.
Show resolved Hide resolved
* ),
* ),
* )
Expand All @@ -52,6 +53,10 @@ class CRedisCache extends CCache
* @var int the port to use for connecting to the redis server. Default port is 6379.
*/
public $port=6379;
/**
* @var string the username to use to authenticate with the redis server. If set, AUTH command will be sent with username.
*/
public $username;
/**
* @var string the password to use to authenticate with the redis server. If not set, no AUTH command will be sent.
*/
Expand Down Expand Up @@ -96,8 +101,14 @@ protected function connect()
{
if($this->ssl)
stream_socket_enable_crypto($this->_socket,true,STREAM_CRYPTO_METHOD_TLS_CLIENT);
if($this->password!==null)
$this->executeCommand('AUTH',array($this->password));
if ($this->password !== null) {
if ($this->username !== null) {
$this->executeCommand('AUTH',array($this->username, $this->password));
} else {
$this->executeCommand('AUTH',array($this->password));
}
}

$this->executeCommand('SELECT',array($this->database));
}
else
Expand Down