mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 00:20:37 +01:00
MDL-83085 redis: Use named parameters if supported
This commit is contained in:
parent
1938c438ea
commit
a933455be2
31
cache/stores/redis/lib.php
vendored
31
cache/stores/redis/lib.php
vendored
@ -267,11 +267,38 @@ class cachestore_redis extends store implements
|
||||
$redis = null;
|
||||
try {
|
||||
// Create a $redis object of a RedisCluster or Redis class.
|
||||
$phpredisversion = phpversion('redis');
|
||||
if ($clustermode) {
|
||||
$redis = new RedisCluster(null, $trimmedservers, 1, 1, true, $password, !empty($opts) ? $opts : null);
|
||||
if (version_compare($phpredisversion, '6.0.0', '>=')) {
|
||||
// Named parameters are fully supported starting from version 6.0.0.
|
||||
$redis = new RedisCluster(
|
||||
name: null,
|
||||
seeds: $trimmedservers,
|
||||
timeout: 1,
|
||||
read_timeout: 1,
|
||||
persistent: true,
|
||||
auth: $password,
|
||||
context: !empty($opts) ? $opts : null,
|
||||
);
|
||||
} else {
|
||||
$redis = new RedisCluster(null, $trimmedservers, 1, 1, true, $password, !empty($opts) ? $opts : null);
|
||||
}
|
||||
} else {
|
||||
$redis = new Redis();
|
||||
$redis->connect($server, $port, 1, null, 100, 1, $opts);
|
||||
if (version_compare($phpredisversion, '6.0.0', '>=')) {
|
||||
// Named parameters are fully supported starting from version 6.0.0.
|
||||
$redis->connect(
|
||||
host: $server,
|
||||
port: $port,
|
||||
timeout: 1,
|
||||
retry_interval: 100,
|
||||
read_timeout: 1,
|
||||
context: $opts,
|
||||
);
|
||||
} else {
|
||||
$redis->connect($server, $port, 1, null, 100, 1, $opts);
|
||||
}
|
||||
|
||||
if (!empty($password)) {
|
||||
$redis->auth($password);
|
||||
}
|
||||
|
@ -270,27 +270,40 @@ class redis extends handler implements SessionHandlerInterface {
|
||||
// Make a connection to Redis server(s).
|
||||
try {
|
||||
// Create a $redis object of a RedisCluster or Redis class.
|
||||
$phpredisversion = phpversion('redis');
|
||||
if ($this->clustermode) {
|
||||
$this->connection = new \RedisCluster(
|
||||
name: null,
|
||||
seeds: $trimmedservers,
|
||||
timeout: 1,
|
||||
readTimeout: 1,
|
||||
persistent: true,
|
||||
auth: $this->auth,
|
||||
context: !empty($opts) ? $opts : null,
|
||||
);
|
||||
if (version_compare($phpredisversion, '6.0.0', '>=')) {
|
||||
// Named parameters are fully supported starting from version 6.0.0.
|
||||
$this->connection = new \RedisCluster(
|
||||
name: null,
|
||||
seeds: $trimmedservers,
|
||||
timeout: 1,
|
||||
read_timeout: 1,
|
||||
persistent: true,
|
||||
auth: $this->auth,
|
||||
context: !empty($opts) ? $opts : null,
|
||||
);
|
||||
} else {
|
||||
$this->connection = new \RedisCluster(null, $trimmedservers, 1, 1, true,
|
||||
$this->auth, !empty($opts) ? $opts : null);
|
||||
}
|
||||
} else {
|
||||
$delay = rand(100, 500);
|
||||
$this->connection = new \Redis();
|
||||
$this->connection->connect(
|
||||
host: $server,
|
||||
port: $port,
|
||||
timeout: 1,
|
||||
retry_interval: $delay,
|
||||
read_timeout: 1,
|
||||
context: $opts,
|
||||
);
|
||||
if (version_compare($phpredisversion, '6.0.0', '>=')) {
|
||||
// Named parameters are fully supported starting from version 6.0.0.
|
||||
$this->connection->connect(
|
||||
host: $server,
|
||||
port: $port,
|
||||
timeout: 1,
|
||||
retry_interval: $delay,
|
||||
read_timeout: 1,
|
||||
context: $opts,
|
||||
);
|
||||
} else {
|
||||
$this->connection->connect($server, $port, 1, null, $delay, 1, $opts);
|
||||
}
|
||||
|
||||
if ($this->auth !== '' && !$this->connection->auth($this->auth)) {
|
||||
throw new $exceptionclass('Unable to authenticate.');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user