Skip to content

Commit

Permalink
MDL-83753 redis: Allow for configurable max retries setting
Browse files Browse the repository at this point in the history
  • Loading branch information
djarran committed Dec 19, 2024
1 parent afd174f commit 6f581a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
// $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.
// $CFG->session_redis_maxretries = 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!
Expand Down
9 changes: 8 additions & 1 deletion lib/classes/session/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class redis extends handler {
/** @var int $timeout How long sessions live before expiring. */
protected $timeout;

/** @var int Maximum number of retries for cache store operations. */
protected int $maxretries = 3;

/** @var int $connectiontimeout The number of seconds to wait for a connection or response from the Redis server. */
protected int $connectiontimeout = 3;

Expand Down Expand Up @@ -199,6 +202,10 @@ public function __construct() {
if (isset($CFG->session_redis_connection_timeout)) {
$this->connectiontimeout = (int)$CFG->session_redis_connection_timeout;
}

if (isset($CFG->session_redis_max_retries)) {
$this->maxretries = (int)$CFG->session_redis_max_retries;
}
}

/**
Expand Down Expand Up @@ -246,7 +253,7 @@ public function init() {

// MDL-59866: Add retries for connections (up to 5 times) to make sure it goes through.
$counter = 1;
$maxnumberofretries = 5;
$maxnumberofretries = $this->maxretries;
$opts = [];
if ($this->sslopts) {
// Do not set $opts['stream'] = [], breaks connect().
Expand Down

0 comments on commit 6f581a1

Please sign in to comment.