8000 [Cache] Enforce usage of Predis with Sentinel · symfony/symfony@86a7e1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 86a7e1c

Browse 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

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines 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::cr 8000 eateConnection($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

Lines 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