Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6eb46d8

Browse filesBrowse files
committed
adjustments from PR
1 parent ed47b24 commit 6eb46d8
Copy full SHA for 6eb46d8

File tree

Expand file treeCollapse file tree

3 files changed

+22
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-4
lines changed

‎src/Symfony/Component/Cache/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/CHANGELOG.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
CHANGELOG
22
=========
33

4+
4.4.0
5+
-----
6+
7+
* added support for connecting to Redis Sentinel clusters
8+
49
4.3.0
510
-----
611

712
* removed `psr/simple-cache` dependency, run `composer require psr/simple-cache` if you need it
813
* deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead
914
* deprecated `SimpleCacheAdapter`, use `Psr16Adapter` instead
10-
* added support for connecting to Redis Sentinel clusters
1115

1216
4.2.0
1317
-----

‎src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
use Symfony\Component\Cache\Adapter\AbstractAdapter;
15+
use Symfony\Component\Cache\Adapter\RedisAdapter;
1516

1617
class RedisAdapterSentinelTest extends AbstractRedisAdapterTest
1718
{
@@ -29,4 +30,14 @@ public static function setupBeforeClass()
2930

3031
self::$redis = AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['redis_sentinel' => $service]);
3132
}
33+
34+
/**
35+
* @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
36+
* @expectedExceptionMessage Invalid Redis DSN: cannot use both redis_cluster and redis_sentinel at the same time
37+
*/
38+
public function testInvalidDSNHasBothClusterAndSentinel()
39+
{
40+
$dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster';
41+
RedisAdapter::createConnection($dsn);
42+
}
3243
}

‎src/Symfony/Component/Cache/Traits/RedisTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ trait RedisTrait
3838
'tcp_keepalive' => 0,
3939
'lazy' => null,
4040
'redis_cluster' => false,
41-
'redis_sentinel' => false,
41+
'redis_sentinel' => null,
4242
'dbindex' => 0,
4343
'failover' => 'none',
4444
];
@@ -153,7 +153,7 @@ public static function createConnection($dsn, array $options = [])
153153

154154
$params += $query + $options + self::$defaultConnectionOptions;
155155

156-
if (null === $params['class'] && !$params['redis_sentinel'] && \extension_loaded('redis')) {
156+
if (null === $params['class'] && !isset($params['redis_sentinel']) && \extension_loaded('redis')) {
157157
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class);
158158
} else {
159159
$class = null === $params['class'] ? \Predis\Client::class : $params['class'];
@@ -251,7 +251,10 @@ public static function createConnection($dsn, array $options = [])
251251
} elseif (is_a($class, \Predis\Client::class, true)) {
252252
if ($params['redis_cluster']) {
253253
$params['cluster'] = 'redis';
254-
} elseif ($params['redis_sentinel']) {
254+
if (isset($params['redis_sentinel'])) {
255+
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: cannot use both redis_cluster and redis_sentinel at the same time: %s', $dsn));
256+
}
257+
} elseif (isset($params['redis_sentinel'])) {
255258
$params['replication'] = 'sentinel';
256259
$params['service'] = $params['redis_sentinel'];
257260
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.