Commit a5a64dd7 by Carsten Brandt

improved redis timeout handling

parent 133e5c6e
......@@ -63,7 +63,11 @@ class RedisCache extends Cache
/**
* @var float timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
*/
public $timeout = null;
public $connectionTimeout = null;
/**
* @var float timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
*/
public $dataTimeout = null;
/**
* @var \yii\db\redis\Connection the redis connection
*/
......@@ -92,7 +96,8 @@ class RedisCache extends Cache
$this->_connection = new Connection(array(
'dsn' => 'redis://' . $this->hostname . ':' . $this->port . '/' . $this->database,
'password' => $this->password,
'timeout' => $this->timeout,
'connectionTimeout' => $this->connectionTimeout,
'dataTimeout' => $this->dataTimeout,
));
}
return $this->_connection;
......
......@@ -48,7 +48,11 @@ class Connection extends Component
/**
* @var float timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
*/
public $timeout = null;
public $connectionTimeout = null;
/**
* @var float timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
*/
public $dataTimeout = null;
/**
* @var array List of available redis commands http://redis.io/commands
......@@ -245,9 +249,12 @@ class Connection extends Component
$host,
$errorNumber,
$errorDescription,
$this->timeout ? $this->timeout : ini_get("default_socket_timeout")
$this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout")
);
if ($this->_socket) {
if ($this->dataTimeout !== null) {
stream_set_timeout($this->_socket, $timeout=(int)$this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000));
}
if ($this->password !== null) {
$this->executeCommand('AUTH', array($this->password));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment