Skip to content
Open
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
9 changes: 7 additions & 2 deletions Queue/Backend/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Redis implements Backend
protected $port;
protected $timeout;
protected $password;
protected $username;

/**
* @var int
Expand Down Expand Up @@ -264,7 +265,7 @@ protected function connect()
$success = $this->redis->connect($this->host, $this->port, $this->timeout, null, 100);

if ($success && !empty($this->password)) {
$success = $this->redis->auth($this->password);
$success = $this->redis->auth($this->password, $this->username);
}

if (!empty($this->database) || 0 === $this->database) {
Expand All @@ -279,7 +280,8 @@ public function setConfig(
$port,
$timeout,
#[\SensitiveParameter]
$password
$password,
$username = null
) {
$this->disconnect();

Expand All @@ -290,6 +292,9 @@ public function setConfig(
if (!empty($password)) {
$this->password = $password;
}
if (!empty($username)) {
$this->username = $username;
}
}

private function disconnect()
Expand Down
2 changes: 1 addition & 1 deletion Queue/Backend/Sentinel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function connect()
$this->timeout = 0.05;
}

$client = new \Credis_Client($master[0], $master[1], $this->timeout, $persistent = false, $this->database, $this->password);
$client = new \Credis_Client($master[0], $master[1], $this->timeout, $persistent = false, $this->database, $this->password, $this->username);
$client->connect();

$this->redis = $client;
Expand Down
3 changes: 2 additions & 1 deletion Queue/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static function makeBackendFromSettings(SystemSettings $settings)
$host = $settings->redisHost->getValue();
$port = $settings->redisPort->getValue();
$timeout = $settings->redisTimeout->getValue();
$username = $settings->redisUsername->getValue();
$password = $settings->redisPassword->getValue();
$database = $settings->redisDatabase->getValue();

Expand All @@ -83,7 +84,7 @@ public static function makeBackendFromSettings(SystemSettings $settings)
$redis->setDatabase($database);
}

$redis->setConfig($host, $port, $timeout, $password);
$redis->setConfig($host, $port, $timeout, $password, $username);
return $redis;
}
}
16 changes: 16 additions & 0 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
/** @var Setting */
public $redisDatabase;

/** @var Setting */
public $redisUsername;

/** @var Setting */
public $redisPassword;

Expand Down Expand Up @@ -90,6 +93,7 @@ protected function init()
$this->redisHost = $this->createRedisHostSetting();
$this->redisPort = $this->createRedisPortSetting();
$this->redisTimeout = $this->createRedisTimeoutSetting();
$this->redisUsername = $this->createRedisUsernameSetting();
$this->redisDatabase = $this->createRedisDatabaseSetting();
$this->redisPassword = $this->createRedisPasswordSetting();
$this->queueEnabled = $this->createQueueEnabledSetting();
Expand Down Expand Up @@ -235,6 +239,18 @@ private function createNumberOfQueueWorkerSetting()
return $numQueueWorkers;
}

private function createRedisUsernameSetting()
{
return $this->makeSetting('redisUsername', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Redis Username';
$field->condition = 'backend=="redis"';
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
$field->uiControlAttributes = array('size' => 128);
$field->inlineHelp = 'Username for Redis ACL authentication. Leave empty if not used.';
$field->validators[] = new CharacterLength(null, 128);
});
}

private function createRedisPasswordSetting()
{
return $this->makeSetting('redisPassword', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
Expand Down
Loading