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

[Cache] Send Predis SSL options in the $hosts parameter#50074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@magnusnordlander
Copy link
Contributor

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#46465
LicenseMIT

Predis accepts SSL options in the$hosts parameter, not in the$params parameter. From my perspective, this is really only applicable when usingrediss://host:port style DSNs, where you might want to add?ssl[verify_peer]=0 or something similar.

I'm unsure how to write a good test for this, since there doesn't seem to be any standard Redis host with TLS that requires additional options in the test runner. Happy to take suggestions on how to approach a test, if that's deemed necessary.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you confirm that this change would still work?

diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.phpindex e326dba76b..a35859d2b6 100644--- a/src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php+++ b/src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php@@ -48,4 +48,29 @@ class PredisAdapterTest extends AbstractRedisAdapterTestCase         ];         $this->assertSame($params, $connection->getParameters()->toArray());     }++    public function testCreateSslConnection()+    {+        $redisHost = getenv('REDIS_HOST');++        $redis = RedisAdapter::createConnection('rediss://'.$redisHost.'/1?ssl[verify_peer]=0', ['class' => \Predis\Client::class, 'timeout' => 3]);+        $this->assertInstanceOf(\Predis\Client::class, $redis);++        $connection = $redis->getConnection();+        $this->assertInstanceOf(StreamConnection::class, $connection);++        $redisHost = explode(':', $redisHost);+        $params = [+            'scheme' => 'tls',+            'host' => $redisHost[0],+            'port' => (int) ($redisHost[1] ?? 6379),+            'ssl' => ['verify_peer' => '0'],+            'persistent' => 0,+            'timeout' => 3,+            'read_write_timeout' => 0,+            'tcp_nodelay' => true,+            'database' => '1',+        ];+        $this->assertSame($params, $connection->getParameters()->toArray());+    } }diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.phpindex 07633a9d3f..67d8663169 100644--- a/src/Symfony/Component/Cache/Traits/RedisTrait.php+++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php@@ -349,7 +349,7 @@ trait RedisTrait             }             $params['exceptions'] = false;-            $redis = new $class($hosts, array_diff_key($params, array_diff_key(self::$defaultConnectionOptions, ['ssl' => null])));+            $redis = new $class($hosts, array_diff_key($params, self::$defaultConnectionOptions));             if (isset($params['redis_sentinel'])) {                 $redis->getConnection()->setSentinelTimeout($params['timeout']);             }

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I applied my patch, please report back if there's an issue with it.

@nicolas-grekas
Copy link
Member

Thank you@magnusnordlander.

@nicolas-grekasnicolas-grekas merged commit638703d intosymfony:5.4Apr 21, 2023
This was referencedApr 28, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

4 participants

@magnusnordlander@nicolas-grekas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp