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 3a47e5f

Browse filesBrowse files
bug #46401 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option (buffcode)
This PR was merged into the 4.4 branch. Discussion ---------- [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT Enforce usage of `\Predis\Client` when the `redis_sentinel` option is enabled. Otherwise it is possible to give the option `class: Redis`, which will setup the connection without any error but fail to work, because the Redis commands will be issued against the Sentinel instances instead of the Redis instances. Commits ------- cdc9414 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option
2 parents 5b265a0 + cdc9414 commit 3a47e5f
Copy full SHA for 3a47e5f

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('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
}

‎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('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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.