From a5a64dd7c9a1f753f8745f92230ff30204af0bdf Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 12 Aug 2013 01:16:34 +0200 Subject: [PATCH] improved redis timeout handling --- framework/yii/caching/RedisCache.php | 9 +++++++-- framework/yii/db/redis/Connection.php | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/yii/caching/RedisCache.php b/framework/yii/caching/RedisCache.php index e988c2d..0c8bf15 100644 --- a/framework/yii/caching/RedisCache.php +++ b/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") */ - 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; diff --git a/framework/yii/db/redis/Connection.php b/framework/yii/db/redis/Connection.php index 72c80de..781701b 100644 --- a/framework/yii/db/redis/Connection.php +++ b/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") */ - 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)); }