diff --git a/CHANGELOG.md b/CHANGELOG.md index df34c7b..8c0a3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +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 - 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..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 { @@ -305,13 +307,15 @@ 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); 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/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..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; @@ -75,6 +76,24 @@ 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 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();