8000 Merge branch '6.0' into 6.1 · symfony/cache@5cf8e75 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 5cf8e75

Browse files
Merge branch '6.0' into 6.1
* 6.0: [HttpKernel] Fix test sensitivity on xdebug.file_link_format [HttpKernel] Fix non-scalar check in surrogate fragment renderer [Debug][ErrorHandler] fix operator precedence [Cache] Ensured that redis adapter can use multiple redis sentinel hosts [DoctrineBridge] fix tests [Security] Allow redirect after login to absolute URLs
2 parents e855b4b + 8c98079 commit 5cf8e75

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Tests/Adapter/RedisAdapterSentinelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function testInvalidDSNHasBothClusterAndSentinel()
4747
public function testExceptionMessageWhenFailingToRetrieveMasterInformation()
4848
{
4949
$hosts = getenv('REDIS_SENTINEL_HOSTS');
50-
$firstHost = explode(' ', $hosts)[0];
50+
$dsn = 'redis:?host['.str_replace(' ', ']&host[', $hosts).']';
5151
$this->expectException(\Symfony\Component\Cache\Exception\InvalidArgumentException::class);
52-
$this->expectExceptionMessage('Failed to retrieve master information from master name "invalid-masterset-name" and address "'.$firstHost.'".');
53-
AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['redis_sentinel' => 'invalid-masterset-name']);
52+
$this->expectExceptionMessage('Failed to retrieve master information from sentinel "invalid-masterset-name" and dsn "'.$dsn.'".');
53+
AbstractAdapter::createConnection($dsn, ['redis_sentinel' => 'invalid-masterset-name']);
5454
}
5555
}

Traits/RedisTrait.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static function createConnection(string $dsn, array $options = []): \Redi
174174
}
175175

176176
if (null === $params['class'] && \extension_loaded('redis')) {
177-
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class);
177+
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) && !isset($params['redis_sentinel']) ? \RedisArray::class : \Redis::class);
178178
} else {
179179
$class = $params['class'] ?? \Predis\Client::class;
180180

@@ -188,21 +188,29 @@ public static function createConnection(string $dsn, array $options = []): \Redi
188188
$redis = new $class();
189189

190190
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts, $tls) {
191-
$host = $hosts[0]['host'] ?? $hosts[0]['path'];
192-
$port = $hosts[0]['port'] ?? 0;
191+
$hostIndex = 0;
192+
do {
193+
$host = $hosts[$hostIndex]['host'] ?? $hosts[$hostIndex]['path'];
194+
$port = $hosts[$hostIndex]['port'] ?? 0;
195+
$address = false;
196+
197+
if (isset($hosts[$hostIndex]['host']) && $tls) {
198+
$host = 'tls://'.$host;
199+
}
193200

194-
if (isset($hosts[0]['host']) && $tls) {
195-
$host = 'tls://'.$host;
196-
}
201+
if (!isset($params['redis_sentinel'])) {
202+
break;
203+
}
197204

198-
if (isset($params['redis_sentinel'])) {
199205
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
200206

201-
if (!$address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
202-
throw new InvalidArgumentException(sprintf('Failed to retrieve master information from master name "%s" and address "%s:%d".', $params['redis_sentinel'], $host, $port));
207+
if ($address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
208+
[$host, $port] = $address;
203209
}
210+
} while (++$hostIndex < \count($hosts) && !$address);
204211

205-
[$host, $port] = $address;
212+
if (isset($params['redis_sentinel']) && !$address) {
213+
throw new InvalidArgumentException(sprintf('Failed to retrieve master information from sentinel "%s" and dsn "%s".', $params['redis_sentinel'], $dsn));
206214
}
207215

208216
try {

0 commit comments

Comments
 (0)
0