Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

5.1.3 - 2025-09-01
- Add support for Sentinel password

5.1.2 - 2025-07-07
- Textual changes

Expand Down
13 changes: 13 additions & 0 deletions Queue/Backend/Sentinel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class Sentinel extends Redis
{
private $masterName = '';

/*
* @var bool
*/
private $usePasswordForSentinelInstances = false;

protected function connect()
{
$hosts = explode(',', $this->host);
Expand All @@ -36,6 +41,9 @@ protected function connect()
$configuredClient = new \Credis_Client($host, $ports[$index], $timeout = 0.5, $persistent = false);
$configuredClient->forceStandalone();
$configuredClient->connect();
if ($this->usePasswordForSentinelInstances && !empty($this->password)) {
$configuredClient->auth($this->password);
}
$configuredSentinel = new \Credis_Sentinel($configuredClient);
$master = $configuredSentinel->getMasterAddressByName($this->masterName);

Expand Down Expand Up @@ -64,6 +72,11 @@ public function setSentinelMasterName($name)
$this->masterName = $name;
}

public function setUsePasswordForSentinelInstances(bool $usePasswordForSentinelInstances)
{
$this->usePasswordForSentinelInstances = $usePasswordForSentinelInstances;
}

protected function evalScript($script, $keys, $args)
{
return $this->redis->eval($script, $keys, $args);
Expand Down
3 changes: 3 additions & 0 deletions Queue/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public static function makeBackendFromSettings(SystemSettings $settings)
$redis = new Queue\Backend\Sentinel();
$redis->setSentinelMasterName($masterName);
$redis->setDatabase($database);
if (!empty($settings->getUsePasswordForSentinelInstances())) {
$redis->setUsePasswordForSentinelInstances(true);
}
}
} elseif ($settings->isUsingClusterBackend()) {
$redis = new Queue\Backend\RedisCluster();
Expand Down
19 changes: 19 additions & 0 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
/** @var Setting */
public $sentinelMasterName;

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

public function getAvailableRedisBackendTypes()
{
return array(
Expand All @@ -83,6 +86,7 @@ protected function init()
$this->backend = $this->createBackendSetting();
$this->useWhatRedisBackendType = $this->createUseWhatRedisBackendType();
$this->sentinelMasterName = $this->createSetSentinelMasterName();
$this->usePasswordForSentinelInstances = $this->createUsePasswordForSentinelInstances();
$this->redisHost = $this->createRedisHostSetting();
$this->redisPort = $this->createRedisPortSetting();
$this->redisTimeout = $this->createRedisTimeoutSetting();
Expand Down Expand Up @@ -114,6 +118,11 @@ public function getSentinelMasterName()
return $this->sentinelMasterName->getValue();
}

public function getUsePasswordForSentinelInstances()
{
return $this->usePasswordForSentinelInstances->getValue();
}

public function isUsingUnixSocket()
{
return substr($this->redisHost->getValue(), 0, 1) === '/';
Expand Down Expand Up @@ -373,6 +382,16 @@ private function createSetSentinelMasterName()
});
}

private function createUsePasswordForSentinelInstances()
{
return $this->makeSetting('usePasswordForSentinelInstances', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('QueuedTracking_UsePasswordForSentinelsTitle');
$field->condition = 'backend=="redis"';
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->inlineHelp = Piwik::translate('QueuedTracking_UsePasswordForSentinelsHelp', ['</br></br>']) . '</br>';
});
}

public function checkMatchHostsAndPorts()
{
$hosts = $this->redisHost->getValue();
Expand Down
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"MasterNameFieldTitle": "Redis Sentinel Master name",
"MasterNameFieldHelp": "The sentinel master name only needs to be configured if Sentinel is enabled.",
"NumHostsNotMatchNumPorts": "The number of configured hosts doesn't match the number of configured ports.",
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so."
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so.",
"UsePasswordForSentinelsTitle": "Use password with Redis Sentinels",
"UsePasswordForSentinelsHelp": "Only relevant if Sentinel is enabled.%1$sIf enabled, the Redis password will also be used when authenticating with Sentinel instances to obtain the master connection information. Otherwise, the password is only used to authenticate with the Redis master."
}
}
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "QueuedTracking",
"version": "5.1.2",
"version": "5.1.3",
"description": "Scale your large traffic Matomo service by queuing tracking requests in Redis or MySQL for better performance and reliability when experiencing peaks.",
"theme": false,
"keywords": ["tracker", "tracking", "queue", "redis"],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.