From 39c2a41c770ff8e4cca2a2ac8961512358777a67 Mon Sep 17 00:00:00 2001 From: Hjf288 Date: Wed, 15 May 2024 14:18:33 +0100 Subject: [PATCH] Add connection retries support, default to 0 --- src/Cm/RedisSession/Handler.php | 7 +++++++ src/Cm/RedisSession/Handler/ConfigInterface.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Cm/RedisSession/Handler.php b/src/Cm/RedisSession/Handler.php index beccd8e..5ce45e1 100644 --- a/src/Cm/RedisSession/Handler.php +++ b/src/Cm/RedisSession/Handler.php @@ -81,6 +81,11 @@ class Handler implements \SessionHandlerInterface */ const DEFAULT_TIMEOUT = 2.5; + /** + * Default connection retries + */ + const DEFAULT_RETRIES = 0; + /** * Default compression threshold */ @@ -274,6 +279,7 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r $port = $this->config->getPort() ?: self::DEFAULT_PORT; $pass = $this->config->getPassword() ?: null; $timeout = $this->config->getTimeout() ?: self::DEFAULT_TIMEOUT; + $retries = $this->config->getRetries() ?: self::DEFAULT_RETRIES; $persistent = $this->config->getPersistentIdentifier() ?: ''; $this->_dbNum = $this->config->getDatabase() ?: self::DEFAULT_DATABASE; @@ -361,6 +367,7 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r } else { $this->_redis = new \Credis_Client($host, $port, $timeout, $persistent, 0, $pass); + $this->_redis->setMaxConnectRetries($retries); if ($this->hasConnection() == false) { throw new ConnectionFailedException('Unable to connect to Redis'); } diff --git a/src/Cm/RedisSession/Handler/ConfigInterface.php b/src/Cm/RedisSession/Handler/ConfigInterface.php index a315c20..0584169 100644 --- a/src/Cm/RedisSession/Handler/ConfigInterface.php +++ b/src/Cm/RedisSession/Handler/ConfigInterface.php @@ -74,6 +74,13 @@ public function getPassword(); */ public function getTimeout(); + /** + * Get connection retries + * + * @return float + */ + public function getRetries(); + /** * Get unique string for persistent connections, if empty persistent connection is not used *