From c6a7a3a9ed513d48c13d54cdbc4b9ee1f57a8009 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 5 May 2014 11:43:21 -0700 Subject: [PATCH] Set Redis::OPT_READ_TIMEOUT by default * The value is also configurable just like connectTimeout * This deals with problems like https://github.com/nicolasff/phpredis/issues/99 and https://github.com/nicolasff/phpredis/issues/70 Change-Id: I05e91e05764020854d04673b7decae30359f57e9 --- includes/clientpool/RedisConnectionPool.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/clientpool/RedisConnectionPool.php b/includes/clientpool/RedisConnectionPool.php index 15f0a476a6..36d2731cbe 100644 --- a/includes/clientpool/RedisConnectionPool.php +++ b/includes/clientpool/RedisConnectionPool.php @@ -44,6 +44,8 @@ class RedisConnectionPool { */ /** @var string Connection timeout in seconds */ protected $connectTimeout; + /** @var string Read timeout in seconds */ + protected $readTimeout; /** @var string Plaintext auth password */ protected $password; /** @var bool Whether connections persist */ @@ -76,6 +78,7 @@ class RedisConnectionPool { 'See https://www.mediawiki.org/wiki/Redis#Setup' ); } $this->connectTimeout = $options['connectTimeout']; + $this->readTimeout = $options['readTimeout']; $this->persistent = $options['persistent']; $this->password = $options['password']; if ( !isset( $options['serializer'] ) || $options['serializer'] === 'php' ) { @@ -97,6 +100,9 @@ class RedisConnectionPool { if ( !isset( $options['connectTimeout'] ) ) { $options['connectTimeout'] = 1; } + if ( !isset( $options['readTimeout'] ) ) { + $options['readTimeout'] = 31; // handles up to 30 second blocking commands + } if ( !isset( $options['persistent'] ) ) { $options['persistent'] = false; } @@ -112,6 +118,9 @@ class RedisConnectionPool { * $options include: * - connectTimeout : The timeout for new connections, in seconds. * Optional, default is 1 second. + * - readTimeout : The timeout for operation reads, in seconds. + * Commands like BLPOP can fail if told to wait longer than this. + * Optional, default is 60 seconds. * - persistent : Set this to true to allow connections to persist across * multiple web requests. False by default. * - password : The authentication password, will be sent to Redis in clear text. @@ -216,6 +225,7 @@ class RedisConnectionPool { } if ( $conn ) { + $conn->setOption( Redis::OPT_READ_TIMEOUT, $this->readTimeout ); $conn->setOption( Redis::OPT_SERIALIZER, $this->serializer ); $this->connections[$server][] = array( 'conn' => $conn, 'free' => false ); -- 2.20.1