-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Redis cluster support #17982
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
Redis cluster support #17982
Conversation
|
docker-compose.yml services:
php:
build:
context: .
args:
PHP_MODE: production
restart: unless-stopped
volumes:
- ./:/var/www/html
depends_on:
- redis-node-0
- redis-node-1
- redis-node-2
- redis-node-3
- redis-node-4
- redis-node-5
redis-node-0:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_CLUSTER_CREATOR: yes
REDIS_CLUSTER_REPLICAS: 1
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
depends_on:
- redis-node-1
- redis-node-2
- redis-node-3
- redis-node-4
- redis-node-5
redis-node-1:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-2:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-3:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-4:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
redis-node-5:
image: bitnami/redis-cluster:latest
restart: unless-stopped
environment:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5Edit: networks:
redis-cluster-net:
ipv4_address: 172.18.0.7 |
|
You can run For stan you need to do a Certain stan issues can't be fixed easily, so it may be, that you need to regenerate the baselines for phpstan and psalm |
Co-authored-by: Kevin Pfeifer <[email protected]>
|
I think the changes to |
|
Tests have been updated. There is a separated test for |
markstory
left a comment
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.
Looking good. I left a few comments on test coverage.
src/Cache/Engine/RedisEngine.php
Outdated
| } | ||
|
|
||
| if ($this->_Redis instanceof RedisCluster) { | ||
| foreach ($this->_Redis->_masters() as $masterNode) { |
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.
We should have tests for clear + RedisCluster.
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 explain more? The clear should be covered in the Redis cluster test file
https://github.com/cakephp/cakephp/pull/17982/files#diff-05077d970334dd20377d2fcfdefeda53ed0c9849c172c66c53f8a6cd9a0c75efR337
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.
Interesting, I wonder why codecov had those lines flagged as uncovered.
src/Cache/Engine/RedisEngine.php
Outdated
| $this->_Redis->setOption(Redis::OPT_SCAN, (string)Redis::SCAN_RETRY); | ||
| } | ||
|
|
||
| if ($this->_Redis instanceof RedisCluster) { |
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.
Another place where we should have some test coverage.
| ['host' => '172.18.0.7', 'port' => 6379], | ||
| ['host' => '172.18.0.2', 'port' => 6379], | ||
| ['host' => '172.18.0.3', 'port' => 6379], | ||
| ['host' => '172.18.0.5', 'port' => 6379], | ||
| ['host' => '172.18.0.4', 'port' => 6379], | ||
| ['host' => '172.18.0.6', 'port' => 6379], |
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.
Do we need a 6 node cluster? Couldn't we make due with a 3 node cluster? No need to waste additional resources.
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.
We don't need 6 nodes 3 is fine this was what I used for testing
|
ping @zunnu Anything left to be done? There seems to be a few conflicts. |
Should be good now. |
|
Error: Ignored error pattern #^Comparison operation ">" between (int<0, max>|Redis|false) and 0 results in an error.$# in path /home/runner/work/cakephp/cakephp/src/Cache/Engine/RedisEngine.php was not matched in reported errors. |
@dereuromark Done |
|
@dereuromark Anything else to be done or can this be merged? |
|
I wonder what those test fails are @markstory can maybe sign off. |
|
@dereuromark seems its related to a PHPUnit change since the 2 collection objects are not "equal" anymore. The split package stan issues can be ignored. |
|
ping @zunnu |
| $keys = $this->_Redis->scan($iterator, $masterNode, $pattern, $scanCount); | ||
| $nodes = $this->_Redis instanceof RedisCluster | ||
| ? $this->_Redis->_masters() | ||
| : [null]; |
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.
Why null and not just empty array or array with string?
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 reason for [null] instead of [] or ['some-string'] is to make the loop logic work for both cluster and non-cluster without branching.
If you made $nodes = [] in non-cluster mode, the foreach wouldn’t run at all meaning we would never scan anything.
If you made $nodes = [''] or ['some-string'], the wrapper would have to check for a “fake” node value and ignore it, which is clumsier in my opinion.
By using null im saying we have one logical node to scan in single-node mode, but it has no node address pass null into the wrapper so it knows to call the Redis version of scan.
|
@nicosp If you are happy with it we can move forward now. |
Support for Redis cluster.
I have included a test file but im not sure how to implement it to the Github actions.
To test this I have used a docker-compose file and I will put it as a comment to this PR.