Skip to content

Commit f485d28

Browse files
Merge pull request #57 from hjf288/connect-retries
Add connection retries support
2 parents 5d93866 + 39c2a41 commit f485d28

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Cm/RedisSession/Handler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class Handler implements \SessionHandlerInterface
8181
*/
8282
const DEFAULT_TIMEOUT = 2.5;
8383

84+
/**
85+
* Default connection retries
86+
*/
87+
const DEFAULT_RETRIES = 0;
88+
8489
/**
8590
* Default compression threshold
8691
*/
@@ -274,6 +279,7 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r
274279
$port = $this->config->getPort() ?: self::DEFAULT_PORT;
275280
$pass = $this->config->getPassword() ?: null;
276281
$timeout = $this->config->getTimeout() ?: self::DEFAULT_TIMEOUT;
282+
$retries = $this->config->getRetries() ?: self::DEFAULT_RETRIES;
277283
$persistent = $this->config->getPersistentIdentifier() ?: '';
278284
$this->_dbNum = $this->config->getDatabase() ?: self::DEFAULT_DATABASE;
279285

@@ -361,6 +367,7 @@ public function __construct(ConfigInterface $config, LoggerInterface $logger, $r
361367
}
362368
else {
363369
$this->_redis = new \Credis_Client($host, $port, $timeout, $persistent, 0, $pass);
370+
$this->_redis->setMaxConnectRetries($retries);
364371
if ($this->hasConnection() == false) {
365372
throw new ConnectionFailedException('Unable to connect to Redis');
366373
}

src/Cm/RedisSession/Handler/ConfigInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public function getPassword();
7474
*/
7575
public function getTimeout();
7676

77+
/**
78+
* Get connection retries
79+
*
80+
* @return float
81+
*/
82+
public function getRetries();
83+
7784
/**
7885
* Get unique string for persistent connections, if empty persistent connection is not used
7986
*

0 commit comments

Comments
 (0)