-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stof
reviewed
Apr 20, 2023
There was a problem hiding this 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.php
index 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.php
index 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']);
}
dff3752
to
cd7cd2f
Compare
nicolas-grekas
approved these changes
Apr 21, 2023
There was a problem hiding this 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.
Thank you @magnusnordlander. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.