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
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 1.1.30 under development
- Bug #4544: PHP 8 compatibility: Fix deprecation in CLocale (apphp)
- Bug #4566: PHP 8 compatibility: Fix passing null to string parameter parameter (apphp)
- Enh #4552: Added support for PHP 8.3 (sandippingle, ThePepster, marcovtwout)
- Enh #4559: Added support for Redis ACL authentication with username for Redis 6+ (arfeen)
- Enh #4568: Add missing hungarian translations (albertborsos)

Version 1.1.29 November 14, 2023
Expand Down
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
* ),
* ),
* )
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