Browse Source

improved redis timeout handling

tags/2.0.0-beta
Carsten Brandt 12 years ago
parent
commit
a5a64dd7c9
  1. 9
      framework/yii/caching/RedisCache.php
  2. 11
      framework/yii/db/redis/Connection.php

9
framework/yii/caching/RedisCache.php

@ -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") * @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 * @var \yii\db\redis\Connection the redis connection
*/ */
@ -92,7 +96,8 @@ class RedisCache extends Cache
$this->_connection = new Connection(array( $this->_connection = new Connection(array(
'dsn' => 'redis://' . $this->hostname . ':' . $this->port . '/' . $this->database, 'dsn' => 'redis://' . $this->hostname . ':' . $this->port . '/' . $this->database,
'password' => $this->password, 'password' => $this->password,
'timeout' => $this->timeout, 'connectionTimeout' => $this->connectionTimeout,
'dataTimeout' => $this->dataTimeout,
)); ));
} }
return $this->_connection; return $this->_connection;

11
framework/yii/db/redis/Connection.php

@ -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") * @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 * @var array List of available redis commands http://redis.io/commands
@ -245,9 +249,12 @@ class Connection extends Component
$host, $host,
$errorNumber, $errorNumber,
$errorDescription, $errorDescription,
$this->timeout ? $this->timeout : ini_get("default_socket_timeout") $this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout")
); );
if ($this->_socket) { 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) { if ($this->password !== null) {
$this->executeCommand('AUTH', array($this->password)); $this->executeCommand('AUTH', array($this->password));
} }

Loading…
Cancel
Save