Merge pull request #13329 from MrPetovan/task/13318-redis-unix-socket

Add support for port = 0 in Redis driver
This commit is contained in:
Philipp 2023-08-03 14:53:01 +02:00 committed by GitHub
commit 93fa957921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View file

@ -77,6 +77,12 @@
"npm-asset/textcomplete": "^0.18.2",
"npm-asset/typeahead.js": "^0.11.1"
},
"suggest": {
"ext-imagick": "For faster image processing",
"ext-redis": "To use Redis as a locking or caching provider",
"ext-pdo": "To use PDO as a database driver, has priority over mysqli unless database.disable_pdo is set",
"ext-mysqli": "To use mysqli as a databse driver"
},
"repositories": [
{
"type": "vcs",

View file

@ -57,22 +57,27 @@ class RedisCache extends AbstractCache implements ICanCacheInMemory
$redis_host = $config->get('system', 'redis_host');
$redis_port = $config->get('system', 'redis_port');
$redis_pw = $config->get('system', 'redis_password');
$redis_db = $config->get('system', 'redis_db', 0);
$redis_db = (int)$config->get('system', 'redis_db', 0);
try {
if (!empty($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) {
throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available');
} else if (!@$this->redis->connect($redis_host)) {
throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ' isn\'t available');
if (is_numeric($redis_port) && $redis_port > -1) {
$connection_string = $redis_host . ':' . $redis_port;
if (!@$this->redis->connect($redis_host, $redis_port)) {
throw new CachePersistenceException('Expected Redis server at ' . $connection_string . " isn't available");
}
} else {
$connection_string = $redis_host;
if (!@$this->redis->connect($redis_host)) {
throw new CachePersistenceException('Expected Redis server at ' . $connection_string . ' isn\'t available');
}
}
if (!empty($redis_pw) && !$this->redis->auth($redis_pw)) {
throw new CachePersistenceException('Cannot authenticate redis server at ' . $redis_host . ':' . $redis_port);
throw new CachePersistenceException('Cannot authenticate redis server at ' . $connection_string);
}
if ($redis_db !== 0 && !$this->redis->select($redis_db)) {
throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $redis_host . ':' . $redis_port);
throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $connection_string);
}
} catch (\RedisException $exception) {
throw new CachePersistenceException('Redis connection fails unexpectedly', $exception);

View file

@ -543,11 +543,11 @@ return [
'pushpoll_frequency' => 3,
// redis_host (String)
// Host name of the redis daemon.
// Host name or the path to the Unix domain socket of the Redis daemon.
'redis_host' => '127.0.0.1',
// redis_port (String)
// Port number of the redis daemon.
// redis_port (Integer)
// Port number of the Redis daemon, should be -1 for unix domain socket
'redis_port' => 6379,
// redis_db (Integer)