From 989b236bc8970c56b73b03219333b52636efe75e Mon Sep 17 00:00:00 2001 From: Benjamin Walker Date: Mon, 2 Jun 2025 12:02:55 +1000 Subject: [PATCH] MDL-85336 cachestore_redis: Split connection and read timeouts --- public/cache/stores/redis/addinstanceform.php | 5 ++++ .../stores/redis/lang/en/cachestore_redis.php | 2 ++ public/cache/stores/redis/lib.php | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/public/cache/stores/redis/addinstanceform.php b/public/cache/stores/redis/addinstanceform.php index 9cd816415fa..1a86319bb8e 100644 --- a/public/cache/stores/redis/addinstanceform.php +++ b/public/cache/stores/redis/addinstanceform.php @@ -70,5 +70,10 @@ class cachestore_redis_addinstance_form extends cachestore_addinstance_form { $form->addHelpButton('connectiontimeout', 'connectiontimeout', 'cachestore_redis'); $form->setDefault('connectiontimeout', cachestore_redis::CONNECTION_TIMEOUT); $form->setType('connectiontimeout', PARAM_FLOAT); + + $form->addElement('text', 'readtimeout', get_string('readtimeout', 'cachestore_redis')); + $form->addHelpButton('readtimeout', 'readtimeout', 'cachestore_redis'); + $form->setDefault('readtimeout', cachestore_redis::CONNECTION_TIMEOUT); + $form->setType('readtimeout', PARAM_FLOAT); } } diff --git a/public/cache/stores/redis/lang/en/cachestore_redis.php b/public/cache/stores/redis/lang/en/cachestore_redis.php index c3332562c8f..fdc4471623b 100644 --- a/public/cache/stores/redis/lang/en/cachestore_redis.php +++ b/public/cache/stores/redis/lang/en/cachestore_redis.php @@ -46,6 +46,8 @@ $string['prefix_help'] = 'This prefix is used for all key names on the Redis ser $string['prefixinvalid'] = 'Invalid prefix. You can only use a-z A-Z 0-9-_.'; $string['privacy:metadata:redis'] = 'The Redis cachestore plugin stores data briefly as part of its caching functionality. This data is stored on an Redis server where data is regularly removed.'; $string['privacy:metadata:redis:data'] = 'The various data stored in the cache'; +$string['readtimeout'] = 'Read timeout'; +$string['readtimeout_help'] = 'This sets the number of seconds to wait for a read from the Redis server.'; $string['serializer_igbinary'] = 'Igbinary serializer'; $string['serializer_php'] = 'Default PHP serializer'; $string['server'] = 'Server(s)'; diff --git a/public/cache/stores/redis/lib.php b/public/cache/stores/redis/lib.php index 178a35ec008..4fc318b256f 100644 --- a/public/cache/stores/redis/lib.php +++ b/public/cache/stores/redis/lib.php @@ -122,12 +122,19 @@ class cachestore_redis extends store implements /** - * The number of seconds to wait for a connection or response from the Redis server. + * The number of seconds to wait for a connection response from the Redis server. * * @var float */ protected $connectiontimeout = self::CONNECTION_TIMEOUT; + /** + * The number of seconds to wait for a read from the Redis server. + * + * @var float + */ + protected $readtimeout = self::CONNECTION_TIMEOUT; + /** * Bytes read or written by last call to set()/get() or set_many()/get_many(). * @@ -214,6 +221,9 @@ class cachestore_redis extends store implements if (array_key_exists('connectiontimeout', $configuration)) { $this->connectiontimeout = (float)$configuration['connectiontimeout']; } + if (array_key_exists('readtimeout', $configuration)) { + $this->readtimeout = (float)$configuration['readtimeout']; + } if (array_key_exists('lockwait', $configuration)) { $this->lockwait = (int)$configuration['lockwait']; } @@ -296,7 +306,7 @@ class cachestore_redis extends store implements name: null, seeds: $trimmedservers, timeout: $this->connectiontimeout, // Timeout. - read_timeout: $this->connectiontimeout, // Read timeout. + read_timeout: $this->readtimeout, // Read timeout. persistent: true, auth: $password, context: !empty($opts) ? $opts : null, @@ -306,7 +316,7 @@ class cachestore_redis extends store implements null, $trimmedservers, $this->connectiontimeout, - $this->connectiontimeout, + $this->readtimeout, true, $password, !empty($opts) ? $opts : null, ); @@ -320,7 +330,7 @@ class cachestore_redis extends store implements port: $port, timeout: $this->connectiontimeout, // Timeout. retry_interval: 100, // Retry interval. - read_timeout: $this->connectiontimeout, // Read timeout. + read_timeout: $this->readtimeout, // Read timeout. context: $opts, ); } else { @@ -329,7 +339,7 @@ class cachestore_redis extends store implements $this->connectiontimeout, null, 100, - $this->connectiontimeout, + $this->readtimeout, $opts, ); } @@ -912,6 +922,7 @@ class cachestore_redis extends store implements 'serializer' => $data->serializer, 'compressor' => $data->compressor, 'connectiontimeout' => $data->connectiontimeout, + 'readtimeout' => $data->readtimeout, 'encryption' => $data->encryption, 'cafile' => $data->cafile, 'clustermode' => $data->clustermode, @@ -939,6 +950,9 @@ class cachestore_redis extends store implements if (!empty($config['connectiontimeout'])) { $data['connectiontimeout'] = $config['connectiontimeout']; } + if (!empty($config['readtimeout'])) { + $data['readtimeout'] = $config['readtimeout']; + } if (!empty($config['encryption'])) { $data['encryption'] = $config['encryption']; }