8000 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class"… · symfony/cache@7cdabf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cdabf9

Browse files
buffcodenicolas-grekas
authored andcommitted
[Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option
1 parent 2712128 commit 7cdabf9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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::createConnection($dsn);
4546
}
47+
48+
public function testSentinelRequiresPredis()
49+
{
50+
$this->expectException(CacheException::class);
51+
$this->expectExceptionMessage('Cannot use Redis Sentinel: class "Redis" does not extend "Predis\Client":');
52+
$dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster';
53+
RedisAdapter::createConnection($dsn, ['class' => \Redis::class]);
54+
}
4655
}

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('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client": "%s".', $class, $dsn));
184+
}
181185
}
182186

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

0 commit comments

Comments
 (0)
0