MDL-85336 redis: Split connection and read timeouts

This commit is contained in:
Benjamin Walker
2025-12-08 09:06:27 +10:00
parent 989b236bc8
commit 838ec4527c
3 changed files with 21 additions and 5 deletions
@@ -0,0 +1,8 @@
issueNumber: MDL-85336
notes:
core:
- message: >-
Redis connection timeout settings for cachestores and sessions have been
split into connection timeout and read timeout to allow for finer
control. These settings now also accept floats.
type: improved
+1
View File
@@ -382,6 +382,7 @@ $CFG->admin = 'admin';
// // After 5 seconds it will throttle down to once per second.
// $CFG->session_redis_connection_timeout = 3.0; // Optional, default is 3.0.
// $CFG->session_redis_maxretries = 3; // Optional, default is 3.
// $CFG->session_redis_read_timeout = 3.0; // Optional, default is 3.0.
//
// Use the igbinary serializer instead of the php default one. Note that phpredis must be compiled with
// igbinary support to make the setting to work. Also, if you change the serializer you have to flush the database!
+12 -5
View File
@@ -114,9 +114,12 @@ class redis extends handler implements SessionHandlerInterface {
/** @var clock A clock instance */
protected clock $clock;
/** @var float $connectiontimeout The number of seconds to wait for a connection or response from the Redis server. */
/** @var float $connectiontimeout The number of seconds to wait for a connection response from the Redis server. */
protected float $connectiontimeout = 3.0;
/** @var float $readtimeout The number of seconds to wait for a read from the Redis server. */
protected float $readtimeout = 3.0;
/**
* Create new instance of handler.
*/
@@ -212,6 +215,10 @@ class redis extends handler implements SessionHandlerInterface {
$this->maxretries = (int)$CFG->session_redis_max_retries;
}
if (isset($CFG->session_redis_read_timeout)) {
$this->readtimeout = (float)$CFG->session_redis_read_timeout;
}
$this->clock = di::get(clock::class);
}
@@ -316,7 +323,7 @@ class redis extends handler implements SessionHandlerInterface {
name: null,
seeds: $trimmedservers,
timeout: $this->connectiontimeout, // Timeout.
read_timeout: $this->connectiontimeout, // Read timeout.
read_timeout: $this->readtimeout, // Read timeout.
persistent: true,
auth: $this->auth,
context: !empty($opts) ? $opts : null,
@@ -326,7 +333,7 @@ class redis extends handler implements SessionHandlerInterface {
null,
$trimmedservers,
$this->connectiontimeout,
$this->connectiontimeout,
$this->readtimeout,
true,
$this->auth,
!empty($opts) ? $opts : null
@@ -342,7 +349,7 @@ class redis extends handler implements SessionHandlerInterface {
port: $port,
timeout: $this->connectiontimeout, // Timeout.
retry_interval: $delay,
read_timeout: $this->connectiontimeout, // Read timeout.
read_timeout: $this->readtimeout, // Read timeout.
context: $opts,
);
} else {
@@ -352,7 +359,7 @@ class redis extends handler implements SessionHandlerInterface {
$this->connectiontimeout,
null,
$delay,
$this->connectiontimeout,
$this->readtimeout,
$opts
);
}