[6.x] Normalize scheme in Redis connections #33892
Merged
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.
Description
This PR attempts to improve the consistency between
Predis
andPhpRedis
drivers regarding the configuration of thescheme
.Current behavior
By default both drivers are connecting to the Redis server using
tcp
. It is possible to configure the scheme but each driver requires a different setup:scheme
key in the$parameters
array of its constructor. E.g.'scheme' => 'tls'
.$host
string of its constructor. E.g.tls://127.0.0.1
.In Laravel that means we have to use different configurations in
database.php
:Since #33800 was merged, it is possible to define the scheme using the
url
key forphpredis
. Theurl
being parsed transforms thehost
in the correct format astls://127.0.0.1
:But using the
url
key for the predis driver results in a connection error, because thehost
is again formatted astls://127.0.0.1
but the client has its scheme astcp
internally, so it tries to connect totcp://tls://127.0.0.1:6379
which is invalid.Proposed changes
With this PR, it is possible to use the
scheme
key as well as theurl
key for both drivers, thus improving the consistency in the configuration and allowing to switch drivers more easily:Instead of formatting the
host
inRedisManager
like the aforementioned PR does, it assigns thescheme
key in the configuration, which will be handled in the connectors: ThePredisConnector
will pass it to the client's constructor, and thePhpRedisConnector
will format thehost
using thescheme
if it was defined in the configuration or parsed from theurl
.This change has no breaking changes, as it follows the functionality of the previous PR, allowing
redis://
protocols as well astcp://
andtls://
in theurl
key. It's also compatible with the existing functionality regarding thescheme
key for the predis driver.Summary
scheme
in theurl
key forpredis
scheme
key forphpredis
scheme
in theurl
key forphpredis
remains the samescheme
key forpredis
remains the sameclusters
scheme
orurl
ConfigurationUrlParser
returns the correctdriver
for Redis URLs with scheme