Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitca9a8c1

Browse files
bug#50585 [Cache] Fix RedisTrait::createConnection for cluster (darkanakin41)
This PR was submitted for the 6.3 branch but it was squashed and merged into the 5.4 branch instead.Discussion----------[Cache] Fix RedisTrait::createConnection for cluster| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | No| Deprecations? | No| Tickets |Fix#50509| License | MIT| Doc PR | N/AWhen the dsn contains `redis_cluster=1` or `redis_cluster=true` the value was not properly parsed, and the class generated was not the expected RedisCluster.The reason is that the PHP core function `match` make a `===` check.So, as the dsn is a string, the `$params['redis_cluster']` needs to be force to a boolCommits-------ca8e328 [Cache] Fix RedisTrait::createConnection for cluster
2 parentsdda4e7c +ca8e328 commitca9a8c1

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Cache\Tests\Traits;
13+
14+
usePHPUnit\Framework\SkippedTestSuiteError;
15+
usePHPUnit\Framework\TestCase;
16+
useSymfony\Component\Cache\Traits\RedisTrait;
17+
18+
class RedisTraitTestextends TestCase
19+
{
20+
publicstaticfunctionsetUpBeforeClass():void
21+
{
22+
if (!getenv('REDIS_CLUSTER_HOSTS')) {
23+
thrownewSkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
24+
}
25+
}
26+
27+
/**
28+
* @dataProvider provideCreateConnection
29+
*/
30+
publicfunctiontestCreateConnection(string$dsn,string$expectedClass)
31+
{
32+
if (!class_exists($expectedClass)) {
33+
thrownewSkippedTestSuiteError(sprintf('The "%s" class is required.',$expectedClass));
34+
}
35+
if (!getenv('REDIS_CLUSTER_HOSTS')) {
36+
thrownewSkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
37+
}
38+
39+
$mock =self::getObjectForTrait(RedisTrait::class);
40+
$connection =$mock::createConnection($dsn);
41+
42+
self::assertInstanceOf($expectedClass,$connection);
43+
}
44+
45+
publicstaticfunctionprovideCreateConnection():array
46+
{
47+
$hosts =array_map(function ($host) {returnsprintf('host[%s]',$host); },explode('',getenv('REDIS_CLUSTER_HOSTS')));
48+
49+
return [
50+
[
51+
sprintf('redis:?%s&redis_cluster=1',$hosts[0]),
52+
'RedisCluster',
53+
],
54+
[
55+
sprintf('redis:?%s&redis_cluster=true',$hosts[0]),
56+
'RedisCluster',
57+
],
58+
[
59+
sprintf('redis:?%s',$hosts[0]),
60+
'Redis',
61+
],
62+
[
63+
'dsn' =>sprintf('redis:?%s',implode('&',\array_slice($hosts,0,2))),
64+
'RedisArray',
65+
],
66+
];
67+
}
68+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public static function createConnection(string $dsn, array $options = [])
174174
thrownewCacheException(sprintf('Redis Sentinel support requires the "predis/predis" package or the "redis" extension v5.2 or higher: "%s".',$dsn));
175175
}
176176

177+
if (isset($params['lazy'])) {
178+
$params['lazy'] =filter_var($params['lazy'], \FILTER_VALIDATE_BOOLEAN);
179+
}
180+
$params['redis_cluster'] =filter_var($params['redis_cluster'], \FILTER_VALIDATE_BOOLEAN);
181+
177182
if ($params['redis_cluster'] &&isset($params['redis_sentinel'])) {
178183
thrownewInvalidArgumentException(sprintf('Cannot use both "redis_cluster" and "redis_sentinel" at the same time: "%s".',$dsn));
179184
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp