Skip to content

Commit

Permalink
Merge pull request #57 from hjf288/connect-retries
Browse files Browse the repository at this point in the history
Add connection retries support
  • Loading branch information
colinmollenhour authored May 15, 2024
2 parents 5d93866 + 39c2a41 commit f485d28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Cm/RedisSession/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class Handler implements \SessionHandlerInterface
*/
const DEFAULT_TIMEOUT = 2.5;

/**
* Default connection retries
*/
const DEFAULT_RETRIES = 0;

/**
* Default compression threshold
*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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');
}
Expand Down
7 changes: 7 additions & 0 deletions src/Cm/RedisSession/Handler/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit f485d28

Please sign in to comment.