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 86a7e1c

Browse filesBrowse files
committed
[Cache] Enforce usage of Predis with Sentinel
Enforce usage of \Predis\Client when the Sentinel option is enabled
1 parent 1a7fa5d commit 86a7e1c
Copy full SHA for 86a7e1c

File tree

2 files changed

+13
-0
lines changed
Filter options

2 files changed

+13
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\SkippedTestSuiteError;
1515
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1616
use Symfony\Component\Cache\Adapter\RedisAdapter;
17+
use Symfony\Component\Cache\Exception\CacheException;
1718
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1819

1920
/**
@@ -43,4 +44,12 @@ public function testInvalidDSNHasBothClusterAndSentinel()
4344
$dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster';
4445
RedisAdapter::createConnection($dsn);
4546
}
47+
48+
public function testSentinelRequiresPredis()
49+
{
50+
$this->expectException(CacheException::class);
51+
$this->expectExceptionMessage('Redis Sentinel requires the use of \Predis\Client as class:');
52+
$dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster';
53+
RedisAdapter::createConnection($dsn, ['class' => \Redis::class]);
54+
}
4655
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public static function createConnection($dsn, array $options = [])
178178
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class);
179179
} else {
180180
$class = $params['class'] ?? \Predis\Client::class;
181+
182+
if (isset($params['redis_sentinel']) && !is_a($class, \Predis\Client::class, true)) {
183+
throw new CacheException(sprintf('Redis Sentinel requires the use of \Predis\Client as class: "%s".', $dsn));
184+
}
181185
}
182186

183187
if (is_a($class, \Redis::class, true)) {

0 commit comments

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