-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] handle redis cluster creation by dsn #28300
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
Conversation
0e0598d
to
3fc3261
Compare
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.
Nice, thanks!
Here are some 1st review comments.
I'm not sold on the "redis+cluster" scheme. The reason is that when using Predis, there is another way to configure a cluster proposed in #28175
It would be awesome to be able to have a similar way of declaring a cluster when using either RedisCluster from the extension or from Predis.
Maybe let's merge #28175 as is, rebase this PR on top and refactor it to handle a common URL syntax?
} elseif ($this->redis instanceof \RedisCluster || $this->redis instanceof RedisClusterProxy) { | ||
$keys = array(); | ||
|
||
foreach ($this->redis->_masters() as $nodeParams) { |
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.
Coincidently, I did also fix doClear in #28269, with a slightly different implementation, see
https://github.com/symfony/symfony/pull/28269/files#diff-a87375907f78e0dcbee340d314e3d052L236
For this reason, this should be reverted from this PR.
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.
Ok, i've reverted it.
@@ -45,7 +46,8 @@ public function __construct($redis, array $options = array()) | |||
!$redis instanceof \RedisArray && | |||
!$redis instanceof \RedisCluster && | |||
!$redis instanceof \Predis\Client && | |||
!$redis instanceof RedisProxy | |||
!$redis instanceof RedisProxy && | |||
!$redis instanceof RedisClusterProxy |
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.
the Lock component also needs a similar patch
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.
👍 Done
3fc3261
to
023911c
Compare
I've rebased this PR on master and fixed some conflicts. |
023911c
to
3f6e9c4
Compare
Would |
Yep, there are two modes to select from, both legit choices; |
Something like that?
would work also for memcached: |
399158e
to
a250c51
Compare
I’ve implemented the |
With regards to using For clustering to work with predis, the connection dsn's must be passed in as an array instead of using the factory, or the |
ff2366c
to
1d52b4c
Compare
1d52b4c
to
3549ef7
Compare
|
||
// Predis cluster only supports an array of hosts as first argument, otherwise | ||
// options array is ignored. | ||
$redis = new $class($host, array('cluster' => 'redis')); |
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 believe cluster=redis
should be based on the cluster
dsn parameter. If the dsn parameter is server
, then here it should be redis
, if the dsn parameter is client
, then here it should be predis
.
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.
Like I said in a previous comment, the client part has been not implemented as could involve some other options to be handled, so I think it should be done and discussed in another PR
… to Redis clusters (alekitto) This PR was merged into the 4.2-dev branch. Discussion ---------- [Cache] add RedisClusterProxy to create lazy connections to Redis clusters | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Code provided by @alekitto in #28300 I'm working on an alternative to this PR, but these bits are required. Commits ------- 239a022 [Cache] add RedisClusterProxy to create lazy connections to Redis clusters
Closing in favor of #28713 |
… via DSN (nicolas-grekas) This PR was merged into the 4.2-dev branch. Discussion ---------- [Cache] added support for connecting to Redis clusters via DSN | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Replaces #28300 and #28175 This PR allows configuring a cluster of Redis servers using all available options of either the phpredis extension or the Predis package: - the `redis_cluster=0/1` boolean option configures whether the client should use the Redis cluster protocol; - several hosts can be provided using a syntax very similar to #28598, enabling consistent hashing distribution of keys; - `failover=error/distribute/slaves` can be set to direct reads at slave servers; - extra options are passed as is to the driver (e.g. `profile=2.8`) - Predis per-server settings are also possible, using e.g. `host[localhost][alias]=foo` in the query string, or `host[localhost]=alias%3Dfoo` (ie PHP query arrays or urlencoded key/value pairs) Commits ------- a42e877 [Cache] added support for connecting to Redis clusters via DSN
This PR adds support for
\RedisCluster
connection creation via DSN passingredis+cluster
as protocol (ex:redis+cluster://redis-server-1:6379,redis-server-2:6379
).This allow to have the same configuration for different environments and change only the env var containing the connection string.