Skip to content

Commit

Permalink
MDL-81366 redis: Remove the named parameters
Browse files Browse the repository at this point in the history
Unfortunately, the read_timeout named parameter was not recognized on some machines.
To avoid such errors, this patch removed the named parameter on a single Redis connect() and the Redis cluster.
  • Loading branch information
meirzamoodle committed Mar 28, 2024
1 parent c895def commit ce5b7ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
25 changes: 3 additions & 22 deletions cache/stores/redis/lib.php
Expand Up @@ -215,8 +215,6 @@ protected function new_redis(array $configuration): Redis|RedisCluster|null {
// Set Redis server(s).
$servers = explode("\n", $configuration['server']);
$trimmedservers = [];
// print_r($configuration);
// print_r($servers);
foreach ($servers as $server) {
$server = strtolower(trim($server));
if (!empty($server)) {
Expand Down Expand Up @@ -256,32 +254,15 @@ protected function new_redis(array $configuration): Redis|RedisCluster|null {
}
// Connect to redis.
$redis = null;
// print_r($trimmedservers);
// exit;
try {
// Create a $redis object of a RedisCluster or Redis class.
if ($clustermode) {
$redis = new RedisCluster(
name: null,
seeds: $trimmedservers,
timeout: 1,
read_timeout: 1,
persistent: true,
auth: $password,
context: !empty($opts) ? $opts : null,
);
$redis = new RedisCluster(null, $trimmedservers, 1, 1, true, $password, !empty($opts) ? $opts : null);
} else {
// We only need the first record for the single redis.
list($server, $port) = explode(':', $trimmedservers[0]);
$redis = new Redis();
$redis->connect(
host: $server,
port: $port,
timeout: 1,
retry_interval: 100,
read_timeout: 1,
context: $opts,
);
$redis->connect($server, $port, 1, null, 100, 1, $opts);
if (!empty($password)) {
$redis->auth($password);
}
Expand All @@ -306,7 +287,7 @@ protected function new_redis(array $configuration): Redis|RedisCluster|null {
}
$this->isready = true;
} catch (RedisException | RedisClusterException $e) {
$server = $clustermode ? implode(',', $trimmedservers) : $trimmedservers[0].':'.$port;
$server = $clustermode ? implode(',', $trimmedservers) : $server.':'.$port;
debugging("Failed to connect to Redis at {$server}, the error returned was: {$e->getMessage()}");
$this->isready = false;
}
Expand Down
20 changes: 3 additions & 17 deletions lib/classes/session/redis.php
Expand Up @@ -257,27 +257,13 @@ public function init() {
try {
// Create a $redis object of a RedisCluster or Redis class.
if ($this->clustermode) {
$this->connection = new \RedisCluster(
name: null,
seeds: $trimmedservers,
timeout: 1,
read_timeout: 1,
persistent: true,
auth: $this->auth,
context: !empty($opts) ? $opts : null,
);
$this->connection = new \RedisCluster(null, $trimmedservers, 1, 1, true,
$this->auth, !empty($opts) ? $opts : null);
} else {
$delay = rand(100, 500);
list($server, $port) = explode(':', $trimmedservers[0]);
$this->connection = new \Redis();
$this->connection->connect(
host: $server,
port: $this->port ?? $port,
timeout: 1,
retry_interval: $delay,
read_timeout: 1,
context: $opts,
);
$this->connection->connect($server, $this->port ?? $port, 1, null, $delay, 1, $opts);
if ($this->auth !== '' && !$this->connection->auth($this->auth)) {
throw new $exceptionclass('Unable to authenticate.');
}
Expand Down

0 comments on commit ce5b7ed

Please sign in to comment.