Skip to content

Commit

Permalink
Added REDIS cache configuration property ("username") in cache config…
Browse files Browse the repository at this point in the history
…urations
  • Loading branch information
Muhammad Arfeen committed Oct 4, 2024
1 parent f0ea6bd commit 4905a05
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 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,13 @@ 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 || $this->username!==null){
if(isset($this->username))
$this->executeCommand('AUTH',array($this->username, $this->password));
else
$this->executeCommand('AUTH',array($this->password));
}

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

0 comments on commit 4905a05

Please sign in to comment.