mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 10:56:56 +02:00
MDL-83753 redis: Set connection and read timeouts to configurable value
This commit is contained in:
parent
a97ddeb2a2
commit
50100d3106
2 changed files with 15 additions and 10 deletions
|
@ -370,6 +370,7 @@ $CFG->admin = 'admin';
|
|||
// $CFG->session_redis_lock_expire = 7200; // Optional, defaults to session timeout.
|
||||
// $CFG->session_redis_lock_retry = 100; // Optional wait between lock attempts in ms, default is 100.
|
||||
// // After 5 seconds it will throttle down to once per second.
|
||||
// $CFG->session_redis_connection_timeout = 3; // Optional, default is 3.
|
||||
//
|
||||
// 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!
|
||||
|
|
|
@ -114,8 +114,8 @@ class redis extends handler implements SessionHandlerInterface {
|
|||
/** @var clock A clock instance */
|
||||
protected clock $clock;
|
||||
|
||||
/** @var int The number of seconds to wait for a connection or response from the Redis server. */
|
||||
const CONNECTION_TIMEOUT = 10;
|
||||
/** @var int $connectiontimeout The number of seconds to wait for a connection or response from the Redis server. */
|
||||
protected int $connectiontimeout = 3;
|
||||
|
||||
/**
|
||||
* Create new instance of handler.
|
||||
|
@ -204,6 +204,10 @@ class redis extends handler implements SessionHandlerInterface {
|
|||
$this->compressor = $CFG->session_redis_compressor;
|
||||
}
|
||||
|
||||
if (isset($CFG->session_redis_connection_timeout)) {
|
||||
$this->connectiontimeout = (int)$CFG->session_redis_connection_timeout;
|
||||
}
|
||||
|
||||
$this->clock = di::get(clock::class);
|
||||
}
|
||||
|
||||
|
@ -293,8 +297,8 @@ class redis extends handler implements SessionHandlerInterface {
|
|||
$this->connection = new \RedisCluster(
|
||||
name: null,
|
||||
seeds: $trimmedservers,
|
||||
timeout: self::CONNECTION_TIMEOUT, // Timeout.
|
||||
read_timeout: self::CONNECTION_TIMEOUT, // Read timeout.
|
||||
timeout: $this->connectiontimeout, // Timeout.
|
||||
read_timeout: $this->connectiontimeout, // Read timeout.
|
||||
persistent: true,
|
||||
auth: $this->auth,
|
||||
context: !empty($opts) ? $opts : null,
|
||||
|
@ -303,8 +307,8 @@ class redis extends handler implements SessionHandlerInterface {
|
|||
$this->connection = new \RedisCluster(
|
||||
null,
|
||||
$trimmedservers,
|
||||
self::CONNECTION_TIMEOUT,
|
||||
self::CONNECTION_TIMEOUT,
|
||||
$this->connectiontimeout,
|
||||
$this->connectiontimeout,
|
||||
true,
|
||||
$this->auth,
|
||||
!empty($opts) ? $opts : null
|
||||
|
@ -318,19 +322,19 @@ class redis extends handler implements SessionHandlerInterface {
|
|||
$this->connection->connect(
|
||||
host: $server,
|
||||
port: $port,
|
||||
timeout: self::CONNECTION_TIMEOUT, // Timeout.
|
||||
timeout: $this->connectiontimeout, // Timeout.
|
||||
retry_interval: $delay,
|
||||
read_timeout: self::CONNECTION_TIMEOUT, // Read timeout.
|
||||
read_timeout: $this->connectiontimeout, // Read timeout.
|
||||
context: $opts,
|
||||
);
|
||||
} else {
|
||||
$this->connection->connect(
|
||||
$server,
|
||||
$port,
|
||||
self::CONNECTION_TIMEOUT,
|
||||
$this->connectiontimeout,
|
||||
null,
|
||||
$delay,
|
||||
self::CONNECTION_TIMEOUT,
|
||||
$this->connectiontimeout,
|
||||
$opts
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue