From 465cc7c66ca04b1cbda5abb77d6849bfadd64903 Mon Sep 17 00:00:00 2001 From: Jacob Ransom Date: Tue, 20 Oct 2026 22:38:02 +1300 Subject: [PATCH 1/2] Fix the Redis Cluster backend failing to parse on PHP 7.2 and 7.3 --- CHANGELOG.md | 3 +++ Queue/Backend/RedisCluster.php | 4 +++- plugin.json | 2 +- tests/Integration/Queue/FactoryTest.php | 8 ++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df34c7b..db35b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +5.2.2 +- Fixed the Redis Cluster backend failing with a syntax error on PHP 7.2 and 7.3 + 5.2.1 - 2026-10-20 - Fixed queue processing failing with a fatal error, and some hits being counted twice, after a database deadlock or a MariaDB snapshot isolation conflict; requests hit by a snapshot isolation conflict are now retried - Fixed requests being lost when the retry after a database deadlock or snapshot isolation conflict failed because of a different request diff --git a/Queue/Backend/RedisCluster.php b/Queue/Backend/RedisCluster.php index a9a4d0e..ef7640b 100644 --- a/Queue/Backend/RedisCluster.php +++ b/Queue/Backend/RedisCluster.php @@ -305,7 +305,9 @@ protected function connect() throw new Exception(Piwik::translate('QueuedTracking_NumHostsNotMatchNumPorts')); } - $hostsPorts = array_map(fn($host, $port): string => "$host:$port", $hosts, $ports); + $hostsPorts = array_map(function ($host, $port): string { + return "$host:$port"; + }, $hosts, $ports); try { $this->redis = new \RedisCluster(null, $hostsPorts, $this->timeout, $this->timeout, true, $this->password); diff --git a/plugin.json b/plugin.json index f32e29e..8467f90 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "QueuedTracking", - "version": "5.2.1", + "version": "5.2.2", "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"], diff --git a/tests/Integration/Queue/FactoryTest.php b/tests/Integration/Queue/FactoryTest.php index 020c4d8..f3a7021 100644 --- a/tests/Integration/Queue/FactoryTest.php +++ b/tests/Integration/Queue/FactoryTest.php @@ -75,6 +75,14 @@ public function test_makeBackend_shouldReturnASentinelInstanceIfConfigured() $this->assertTrue($backend instanceof Queue\Backend\Sentinel); } + public function testMakeBackendShouldReturnARedisClusterInstanceIfConfigured() + { + Config::getInstance()->QueuedTracking = ['useWhatRedisBackendType' => '3']; + $backend = Factory::makeBackend(); + Config::getInstance()->QueuedTracking = []; + $this->assertTrue($backend instanceof Queue\Backend\RedisCluster); + } + public function test_makeBackend_shouldConfigureRedis() { $success = Factory::makeBackend()->testConnection(); From e997a79e70677d03622343d7f7527fb4ec3f5592 Mon Sep 17 00:00:00 2001 From: Jacob Ransom Date: Wed, 21 Oct 2026 10:54:24 +1300 Subject: [PATCH 2/2] Import Exception and Piwik in the Redis Cluster backend, so a host and port mismatch reports its message --- CHANGELOG.md | 1 + Queue/Backend/RedisCluster.php | 4 +++- tests/Integration/Queue/FactoryTest.php | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db35b0e..8c0a3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ 5.2.2 - Fixed the Redis Cluster backend failing with a syntax error on PHP 7.2 and 7.3 +- Fixed the Redis Cluster backend failing with a fatal error when the numbers of configured hosts and ports do not match 5.2.1 - 2026-10-20 - Fixed queue processing failing with a fatal error, and some hits being counted twice, after a database deadlock or a MariaDB snapshot isolation conflict; requests hit by a snapshot isolation conflict are now retried diff --git a/Queue/Backend/RedisCluster.php b/Queue/Backend/RedisCluster.php index ef7640b..d23bdb1 100644 --- a/Queue/Backend/RedisCluster.php +++ b/Queue/Backend/RedisCluster.php @@ -11,6 +11,8 @@ namespace Piwik\Plugins\QueuedTracking\Queue\Backend; use Piwik\Log; +use Piwik\Piwik; +use Exception; class RedisCluster extends Redis { @@ -313,7 +315,7 @@ protected function connect() $this->redis = new \RedisCluster(null, $hostsPorts, $this->timeout, $this->timeout, true, $this->password); return true; } catch (Exception $e) { - throw new Exception('Could not connect to redis cluster: ' . $e->getMessage()); + throw new Exception('Could not connect to redis cluster: ' . $e->getMessage(), 0, $e); } } diff --git a/tests/Integration/Queue/FactoryTest.php b/tests/Integration/Queue/FactoryTest.php index f3a7021..f7267c1 100644 --- a/tests/Integration/Queue/FactoryTest.php +++ b/tests/Integration/Queue/FactoryTest.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\QueuedTracking\tests\Integration\Queue; use Piwik\Config; +use Piwik\Piwik; use Piwik\Plugins\QueuedTracking\Queue; use Piwik\Plugins\QueuedTracking\Queue\Factory; use Piwik\Plugins\QueuedTracking\SystemSettings; @@ -83,6 +84,16 @@ public function testMakeBackendShouldReturnARedisClusterInstanceIfConfigured() $this->assertTrue($backend instanceof Queue\Backend\RedisCluster); } + public function testRedisClusterShouldExplainAHostAndPortMismatch() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage(Piwik::translate('QueuedTracking_NumHostsNotMatchNumPorts')); + + $backend = new Queue\Backend\RedisCluster(); + $backend->setConfig('127.0.0.1,127.0.0.2', '6379', 0.0, null); + $backend->getServerVersion(); + } + public function test_makeBackend_shouldConfigureRedis() { $success = Factory::makeBackend()->testConnection();