If nodes of the cluster are not reachable clear the slots cache by vityank · Pull Request #2807 · phpredis/phpredis · GitHub
Skip to content

If nodes of the cluster are not reachable clear the slots cache#2807

Merged
michael-grunder merged 1 commit intophpredis:developfrom
vityank:v6.3.0-fixes
Mar 10, 2026
Merged

If nodes of the cluster are not reachable clear the slots cache#2807
michael-grunder merged 1 commit intophpredis:developfrom
vityank:v6.3.0-fixes

Conversation

@vityank
Copy link
Copy Markdown

@vityank vityank commented Feb 16, 2026

During AWS ElastiCache(redis/valkey) upgrade their system builds completely different cluster(All new masters - Possibly swaps with slaves, we're not sure).
If slots cache is turned on - "Can't communicate with any node in the cluster" error happens with all requests unless PHP_FPM is fully restarted.
This change forces phpredis to issue a cache clear operation in such a case.

@vityank vityank changed the base branch from develop to release/6.3.0 February 16, 2026 17:24
@michael-grunder
Copy link
Copy Markdown
Member

@vityank
Copy link
Copy Markdown
Author

vityank commented Feb 17, 2026

@michael-grunder,
We could also make it optional using something like redis.clusters.recache_slots_on_errors=1,
so it will not affect ppl using standard clusters and only adding/removing nodes with slot migrations w/o full cluster replacement like in managed solutions.

I'm not sure if in this case we also need to call redis_sock_disconnect(c->cmd_sock, 1, 1); or not(It looks like this scenario should already have the connections dead). What do you think?

@michael-grunder
Copy link
Copy Markdown
Member

It seems reasonable to nuke the slot cache when we can't connect to any node. I'll play around with it locally this week. Remapping the keyspace isn't the end of the world. PhpRedis didn't even have slot caching for a few versions of RedisCluster.

@vityank
Copy link
Copy Markdown
Author

vityank commented Mar 10, 2026

Hi @michael-grunder ,
AWS has recently released ElastiCache Valkey update.
We verified that EC update builds completely new cluster and doesn't swap masters with replicas.
We tested the code from this PR on the update sequence.
It worked flawlessly and PHP-FPMs connected to the new cluster with cache enabled without getting stuck in no-nodes state.

@michael-grunder michael-grunder merged commit 52e9065 into phpredis:develop Mar 10, 2026
@michael-grunder
Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants