MDL-66546 caching: Add support to unix:// connections to redis.

This commit is contained in:
Juan Carrera 2023-09-22 09:47:26 +02:00
parent e4d1369475
commit 63a7ce5108
3 changed files with 6 additions and 3 deletions

View File

@ -43,6 +43,7 @@ class cachestore_redis_addinstance_form extends cachestore_addinstance_form {
$form->setType('server', PARAM_TEXT);
$form->addHelpButton('server', 'server', 'cachestore_redis');
$form->addRule('server', get_string('required'), 'required');
$form->addElement('static', 'server_desc', '', get_string('server_desc', 'cachestore_redis'));
$form->addElement('advcheckbox', 'encryption', get_string('encrypt_connection', 'cachestore_redis'));
$form->setType('encryption', PARAM_BOOL);

View File

@ -42,12 +42,13 @@ $string['privacy:metadata:redis:data'] = 'The various data stored in the cache';
$string['serializer_igbinary'] = 'The igbinary serializer.';
$string['serializer_php'] = 'The default PHP serializer.';
$string['server'] = 'Server';
$string['server_help'] = 'This sets the hostname or IP address of the Redis server to use.';
$string['server_desc'] = 'For Unix socket usage, use the format <strong>/var/redis.sock</strong> or <strong>unix:///var/redis.sock</strong>';
$string['server_help'] = 'This sets the hostname, IP address or Unix socket path of the Redis server to use.';
$string['password'] = 'Password';
$string['password_help'] = 'This sets the password of the Redis server.';
$string['task_ttl'] = 'Free up memory used by expired entries in Redis caches';
$string['test_server'] = 'Test server';
$string['test_server_desc'] = 'Redis server to use for testing.';
$string['test_server_desc'] = 'Redis server to use for testing.<br>For Unix socket usage, use the format <strong>/var/redis.sock</strong> or <strong>unix:///var/redis.sock</strong>';
$string['test_password'] = 'Test server password';
$string['test_password_desc'] = 'Redis test server password.';
$string['test_serializer'] = 'Serializer';

View File

@ -217,7 +217,8 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_
// Check if it isn't a Unix socket to set default port.
$port = null;
$opts = [];
if ($server[0] === '/') {
// Unix sockets can start with / or with unix://.
if ($server[0] === '/' || strpos($server, 'unix://') === 0) {
$port = 0;
} else {
$port = 6379; // No Unix socket so set default port.