Skip to content

Instantly share code, notes, and snippets.

@richsage
Created March 15, 2022 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richsage/219a00f1618214c5904c8e225b14f40e to your computer and use it in GitHub Desktop.
Save richsage/219a00f1618214c5904c8e225b14f40e to your computer and use it in GitHub Desktop.
Moodle Redis TLS support
protected function new_redis($server, $prefix = '', $password = '') {
$redis = new Redis();
// Check if it isn't a Unix socket to set default port.
$port = ($server[0] === '/') ? null : 6379;
// NOTE: This is the change we added
// You can supply eg tls://my.redis.host:6380/ for it to work
// Check for any protocol requirements eg TLS that have been specified.
if (strpos($server, ':')) {
$serverconf = parse_url($server);
$port = $serverconf['port'] ?? $port;
$scheme = $serverconf['scheme'] ?? '';
$host = $serverconf['host'] ?? '';
$server = (strlen($scheme) ? $scheme . '://' : '');
$server .= $host;
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment