10000 Merge branch '4.4' into 5.2 · symfony/cache@1d801d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d801d1

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: make fabbot happy Fix issue 40507: Tabs as separators between tokens [Cache] phpredis: Added full TLS support for RedisCluster
2 parents b8ac312 + 0da1df9 commit 1d801d1

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

Traits/RedisClusterNodeProxy.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
/**
15+
* This file acts as a wrapper to the \RedisCluster implementation so it can accept the same type of calls as
16+
* individual \Redis objects.
17+
*
18+
* Calls are made to individual nodes via: RedisCluster->{method}($host, ...args)'
19+
* according to https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#directed-node-commands
20+
*
21+
* @author Jack Thomas <jack.thomas@solidalpha.com>
22+
*
23+
* @internal
24+
*/
25+
class RedisClusterNodeProxy
26+
{
27+
private $host;
28+
private $redis;
29+
30+
/**
31+
* @param \RedisCluster|RedisClusterProxy $redis
32+
*/
33+
public function __construct(array $host, $redis)
34+
{
35+
$this->host = $host;
36+
$this->redis = $redis;
37+
}
38+
39+
public function __call(string $method, array $args)
40+
{
41+
return $this->redis->{$method}($this->host, ...$args);
42+
}
43+
44+
public function scan(&$iIterator, $strPattern = null, $iCount = null)
45+
{
46+
return $this->redis->scan($iIterator, $this->host, $strPattern, $iCount);
47+
}
48+
}

Traits/RedisTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ trait RedisTrait
4242
'redis_sentinel' => null,
4343
'dbindex' => 0,
4444
'failover' => 'none',
45+
'ssl' => null, // see https://php.net/context.ssl
4546
];
4647
private $redis;
4748
private $marshaller;
@@ -188,7 +189,7 @@ public static function createConnection($dsn, array $options = [])
188189
}
189190

190191
try {
191-
@$redis->{$connect}($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
192+
@$redis->{$connect}($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ['stream' => $params['ssl'] ?? null]);
192193

193194
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
194195
$isConnected = $redis->isConnected();
@@ -251,7 +252,7 @@ public static function createConnection($dsn, array $options = [])
251252
}
252253

253254
try {
254-
$redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $params['auth'] ?? '');
255+
$redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $params['auth'] ?? '', $params['ssl'] ?? null);
255256
} catch (\RedisClusterException $e) {
256257
throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e->getMessage());
257258
}
@@ -300,7 +301,7 @@ public static function createConnection($dsn, array $options = [])
300301
}
301302
$params['exceptions'] = false;
302303

303-
$redis = new $class($hosts, array_diff_key($params, self::$defaultConnectionOptions));
304+
$redis = new $class($hosts, array_diff_key($params, array_diff_key(self::$defaultConnectionOptions, ['ssl' => null])));
304305
if (isset($params['redis_sentinel'])) {
305306
$redis->getConnection()->setSentinelTimeout($params['timeout']);
306307
}
@@ -547,8 +548,7 @@ private function getHosts(): array
547548
} elseif ($this->redis instanceof RedisClusterProxy || $this->redis instanceof \RedisCluster) {
548549
$hosts = [];
549550
foreach ($this->redis->_masters() as $host) {
550-
$hosts[] = $h = new \Redis();
551-
$h->connect($host[0], $host[1]);
551+
$hosts[] = new RedisClusterNodeProxy($host, $this->redis);
552552
}
553553
}
554554

0 commit comments

Comments
 (0)
0