From 7dc873ee6a9687546ba4a9f8da52650641fee3ca Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 16:38:57 +0200 Subject: [PATCH 1/7] add password option for authetication --- src/Cache/Engine/RedisClusterEngine.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Cache/Engine/RedisClusterEngine.php b/src/Cache/Engine/RedisClusterEngine.php index 66de6aa..11ed0dd 100644 --- a/src/Cache/Engine/RedisClusterEngine.php +++ b/src/Cache/Engine/RedisClusterEngine.php @@ -27,6 +27,7 @@ class RedisClusterEngine extends RedisEngine * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable * cache::gc from ever being called automatically. * - `server` array of Redis server hosts. + * - `password` Password for Redis cluster authorisation * - `timeout` timeout in seconds (float). * - `read_timeout` read timeout in seconds (float). * @@ -40,6 +41,7 @@ class RedisClusterEngine extends RedisEngine 'prefix' => 'cake_', 'probability' => 100, 'server' => [], + 'password' => null, 'timeout' => 2, 'read_timeout' => 2, 'failover' => 'none' @@ -54,6 +56,10 @@ public function init(array $config = []) return false; } + if (!class_exists('RedisCluster')) { + return false; + } + parent::init($config); return $this->_connect(); @@ -107,7 +113,7 @@ public function clear($check) protected function _connect() { try { - $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent']); + $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent'], $this->_config['password']); switch ($this->_config['failover']) { case 'error': From 116dd3bb040c08924a9c960077058b18bb3563af Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 17:28:41 +0200 Subject: [PATCH 2/7] fix composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20fc4fc..14abf76 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "riesenia/cakephp-rediscluster", + "name": "tigerduck42/cakephp-rediscluster", "description": "CakePHP 3.x cache engine for Redis Cluster", "license": "MIT", "authors": [ From 0e1f38b3bef7a76c98ec64c41562463859f15399 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 17:57:30 +0200 Subject: [PATCH 3/7] be backwards compatible --- src/Cache/Engine/RedisClusterEngine.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Cache/Engine/RedisClusterEngine.php b/src/Cache/Engine/RedisClusterEngine.php index 11ed0dd..6219b48 100644 --- a/src/Cache/Engine/RedisClusterEngine.php +++ b/src/Cache/Engine/RedisClusterEngine.php @@ -14,6 +14,7 @@ class RedisClusterEngine extends RedisEngine * @var \RedisCluster */ protected $_Redis; + protected $_redisExtensionVersion; /** * The default config used unless overridden by runtime configuration. @@ -54,6 +55,8 @@ public function init(array $config = []) { if (!extension_loaded('redis')) { return false; + } else { + $this->_redisExtensionVersion = filter_var(phpversion('redis'), FILTER_SANITIZE_NUMBER_INT); } if (!class_exists('RedisCluster')) { @@ -113,8 +116,15 @@ public function clear($check) protected function _connect() { try { - $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent'], $this->_config['password']); + if (400 <= $this->_redisExtensionVersion) { + $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent'], $this->_config['password']); + } else { + if (isset($this->_config['password']) && null !== $this->_config['password']) { + trigger_error("Password not supported prior phpredis prior 4.0.0", E_USER_ERROR); + } + $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent']); + } switch ($this->_config['failover']) { case 'error': $this->_Redis->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_ERROR); From aa44c3d570bd24203c6992f3d0b8dbea13941003 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 18:37:00 +0200 Subject: [PATCH 4/7] use warning instead of error --- src/Cache/Engine/RedisClusterEngine.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Cache/Engine/RedisClusterEngine.php b/src/Cache/Engine/RedisClusterEngine.php index 6219b48..7b46eab 100644 --- a/src/Cache/Engine/RedisClusterEngine.php +++ b/src/Cache/Engine/RedisClusterEngine.php @@ -116,12 +116,11 @@ public function clear($check) protected function _connect() { try { - if (400 <= $this->_redisExtensionVersion) { $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent'], $this->_config['password']); } else { if (isset($this->_config['password']) && null !== $this->_config['password']) { - trigger_error("Password not supported prior phpredis prior 4.0.0", E_USER_ERROR); + trigger_error("Password not supported prior phpredis prior 4.0.0", E_USER_WARNING); } $this->_Redis = new \RedisCluster($this->_config['name'], $this->_config['server'], $this->_config['timeout'], $this->_config['read_timeout'], $this->_config['persistent']); } From 4e3c2fcb87505e2444a6c0b868032d4e347b9e65 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 19:10:20 +0200 Subject: [PATCH 5/7] add me as author --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index 14abf76..4dd7b10 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,10 @@ { "name": "Tomas Saghy", "email": "segy@riesenia.com" + }, + { + "name": "Martin Mitterhauser", + "email": "martin.mitterhauser@gmail.com" } ], "require": { From 2d076fa4cfe57d4406727a36d596999a63fc83e5 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 19:36:16 +0200 Subject: [PATCH 6/7] revert packag name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4dd7b10..a858214 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "tigerduck42/cakephp-rediscluster", + "name": "riesenia/cakephp-rediscluster", "description": "CakePHP 3.x cache engine for Redis Cluster", "license": "MIT", "authors": [ From 5d2ae86558fda103f17295862c3f7f761f97b8f3 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Thu, 27 May 2021 19:41:14 +0200 Subject: [PATCH 7/7] add comment --- src/Cache/Engine/RedisClusterEngine.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Cache/Engine/RedisClusterEngine.php b/src/Cache/Engine/RedisClusterEngine.php index 7b46eab..8d90058 100644 --- a/src/Cache/Engine/RedisClusterEngine.php +++ b/src/Cache/Engine/RedisClusterEngine.php @@ -14,6 +14,11 @@ class RedisClusterEngine extends RedisEngine * @var \RedisCluster */ protected $_Redis; + + /** + * PHP redis extension version + * @var string + */ protected $_redisExtensionVersion; /**