Skip to content

Commit 35268fd

Browse files
authored
Merge pull request #300 from BjoernHelmbold/feature-support-sentinel-auth
Add support for sentinel password
2 parents e5e751c + 808cb6c commit 35268fd

File tree

9 files changed

+42
-2
lines changed

9 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
5.1.3 - 2025-09-01
4+
- Add support for Sentinel password
5+
36
5.1.2 - 2025-07-07
47
- Textual changes
58

Queue/Backend/Sentinel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class Sentinel extends Redis
2222
{
2323
private $masterName = '';
2424

25+
/*
26+
* @var bool
27+
*/
28+
private $usePasswordForSentinelInstances = false;
29+
2530
protected function connect()
2631
{
2732
$hosts = explode(',', $this->host);
@@ -36,6 +41,9 @@ protected function connect()
3641
$configuredClient = new \Credis_Client($host, $ports[$index], $timeout = 0.5, $persistent = false);
3742
$configuredClient->forceStandalone();
3843
$configuredClient->connect();
44+
if ($this->usePasswordForSentinelInstances && !empty($this->password)) {
45+
$configuredClient->auth($this->password);
46+
}
3947
$configuredSentinel = new \Credis_Sentinel($configuredClient);
4048
$master = $configuredSentinel->getMasterAddressByName($this->masterName);
4149

@@ -64,6 +72,11 @@ public function setSentinelMasterName($name)
6472
$this->masterName = $name;
6573
}
6674

75+
public function setUsePasswordForSentinelInstances(bool $usePasswordForSentinelInstances)
76+
{
77+
$this->usePasswordForSentinelInstances = $usePasswordForSentinelInstances;
78+
}
79+
6780
protected function evalScript($script, $keys, $args)
6881
{
6982
return $this->redis->eval($script, $keys, $args);

Queue/Factory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public static function makeBackendFromSettings(SystemSettings $settings)
7272
$redis = new Queue\Backend\Sentinel();
7373
$redis->setSentinelMasterName($masterName);
7474
$redis->setDatabase($database);
75+
if (!empty($settings->getUsePasswordForSentinelInstances())) {
76+
$redis->setUsePasswordForSentinelInstances(true);
77+
}
7578
}
7679
} elseif ($settings->isUsingClusterBackend()) {
7780
$redis = new Queue\Backend\RedisCluster();

SystemSettings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
6060
/** @var Setting */
6161
public $sentinelMasterName;
6262

63+
/** @var Setting */
64+
public $usePasswordForSentinelInstances;
65+
6366
public function getAvailableRedisBackendTypes()
6467
{
6568
return array(
@@ -83,6 +86,7 @@ protected function init()
8386
$this->backend = $this->createBackendSetting();
8487
$this->useWhatRedisBackendType = $this->createUseWhatRedisBackendType();
8588
$this->sentinelMasterName = $this->createSetSentinelMasterName();
89+
$this->usePasswordForSentinelInstances = $this->createUsePasswordForSentinelInstances();
8690
$this->redisHost = $this->createRedisHostSetting();
8791
$this->redisPort = $this->createRedisPortSetting();
8892
$this->redisTimeout = $this->createRedisTimeoutSetting();
@@ -114,6 +118,11 @@ public function getSentinelMasterName()
114118
return $this->sentinelMasterName->getValue();
115119
}
116120

121+
public function getUsePasswordForSentinelInstances()
122+
{
123+
return $this->usePasswordForSentinelInstances->getValue();
124+
}
125+
117126
public function isUsingUnixSocket()
118127
{
119128
return substr($this->redisHost->getValue(), 0, 1) === '/';
@@ -373,6 +382,16 @@ private function createSetSentinelMasterName()
373382
});
374383
}
375384

385+
private function createUsePasswordForSentinelInstances()
386+
{
387+
return $this->makeSetting('usePasswordForSentinelInstances', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
388+
$field->title = Piwik::translate('QueuedTracking_UsePasswordForSentinelsTitle');
389+
$field->condition = 'backend=="redis"';
390+
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
391+
$field->inlineHelp = Piwik::translate('QueuedTracking_UsePasswordForSentinelsHelp', ['</br></br>']) . '</br>';
392+
});
393+
}
394+
376395
public function checkMatchHostsAndPorts()
377396
{
378397
$hosts = $this->redisHost->getValue();

lang/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"MasterNameFieldTitle": "Redis Sentinel Master name",
3434
"MasterNameFieldHelp": "The sentinel master name only needs to be configured if Sentinel is enabled.",
3535
"NumHostsNotMatchNumPorts": "The number of configured hosts doesn't match the number of configured ports.",
36-
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so."
36+
"MultipleServersOnlyConfigurableIfSentinelEnabled": "Multiple hosts or ports can be only configured when Redis Sentinel is on. The plugin README will tell you how to do so.",
37+
"UsePasswordForSentinelsTitle": "Use password with Redis Sentinels",
38+
"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."
3739
}
3840
}

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "QueuedTracking",
3-
"version": "5.1.2",
3+
"version": "5.1.3",
44
"description": "Scale your large traffic Matomo service by queuing tracking requests in Redis or MySQL for better performance and reliability when experiencing peaks.",
55
"theme": false,
66
"keywords": ["tracker", "tracking", "queue", "redis"],
24.6 KB
Loading
24.4 KB
Loading
24.1 KB
Loading

0 commit comments

Comments
 (0)