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.
This commit is contained in:
sam marshall
2022-09-13 10:45:00 +01:00
parent c6211a68b4
commit 4ab9f08ce0
2 changed files with 1 additions and 3 deletions
+1 -2
View File
@@ -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;
}
-1
View File
@@ -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 ";