diff --git a/src/Symfony/Component/Cache/CHANGELOG.md b/src/Symfony/Component/Cache/CHANGELOG.md index 38d60a390d94b..cfabc49a922a8 100644 --- a/src/Symfony/Component/Cache/CHANGELOG.md +++ b/src/Symfony/Component/Cache/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added support for connecting to Redis Sentinel clusters when using the Redis PHP extension + * added TLS support for \Redis connection in the DNS. Example: `redis://127.0.0.1?tls=1` 5.2.0 ----- diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 9e34a6f89dd57..dd5963e75d0d6 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -179,8 +179,14 @@ public static function createConnection($dsn, array $options = []) $connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect'; $redis = new $class(); - $initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) { + $initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts, $query) { $host = $hosts[0]['host'] ?? $hosts[0]['path']; + if (\array_key_exists('tls', $query)) { + $tls = filter_var($query['tls'], \FILTER_VALIDATE_BOOLEAN); + if ($tls) { + $host = 'tls://'.$host; + } + } $port = $hosts[0]['port'] ?? null; if (isset($params['redis_sentinel'])) {