From 4ab9f08ce049d46c76fd34da965e36bf9d3160e1 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Wed, 31 Aug 2022 11:40:34 +0100 Subject: [PATCH] MDL-75369 Redis: Remove unnecessary ping after connect The Redis cache store and session handler both do a 'ping()' after connecting to Redis. This is unnecessary because the connect() call has just checked the network connection and it's hardly likely that the server has gone down since then. According to my profiling, both connect() and ping() take measurable time when talking to a separate server, i.e. a few milliseconds. So it's not the case that connect() doesn't really talk to the server, as I initially wondered. If using Redis on a separate (non-localhost) server for both session and cache store, removing these ping calls can save a millisecond or two per request. --- cache/stores/redis/lib.php | 3 +-- lib/classes/session/redis.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cache/stores/redis/lib.php b/cache/stores/redis/lib.php index 800bff13ac8..8521812ee72 100644 --- a/cache/stores/redis/lib.php +++ b/cache/stores/redis/lib.php @@ -216,8 +216,7 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_ if (!empty($prefix)) { $redis->setOption(Redis::OPT_PREFIX, $prefix); } - // Database setting option... - $this->isready = $this->ping($redis); + $this->isready = true; } else { $this->isready = false; } diff --git a/lib/classes/session/redis.php b/lib/classes/session/redis.php index 605df12c2de..c7e6d407772 100644 --- a/lib/classes/session/redis.php +++ b/lib/classes/session/redis.php @@ -227,7 +227,6 @@ class redis extends handler { throw new RedisException('Unable to select Redis database '.$this->database.'.'); } } - $this->connection->ping(); return true; } catch (RedisException $e) { $logstring = "Failed to connect (try {$counter} out of {$maxnumberofretries}) to redis ";