GeezerVison is showing github.com — Invalidate slot cache on failed cluster connections · phpredis/phpredis@c7b8784
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: cluster_library.c +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1599,11 +1599,13 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char |
1599 | 1599 |
|
1600 | 1600 | // If we've detected the cluster is down, throw an exception |
1601 | 1601 | if (c->clusterdown) { |
| 1602 | + cluster_cache_clear(c); |
1602 | 1603 | CLUSTER_THROW_EXCEPTION("The Redis Cluster is down (CLUSTERDOWN)", 0); |
1603 | 1604 | return -1; |
1604 | 1605 | } else if (timedout || resp == -1) { |
1605 | 1606 | // Make sure the socket is reconnected, it such that it is in a clean state |
1606 | 1607 | redis_sock_disconnect(c->cmd_sock, 1, 1); |
| 1608 | + cluster_cache_clear(c); |
1607 | 1609 |
|
1608 | 1610 | if (timedout) { |
1609 | 1611 | CLUSTER_THROW_EXCEPTION("Timed out attempting to find data in the correct node!", 0); |
@@ -3115,5 +3117,12 @@ PHP_REDIS_API void cluster_cache_store(zend_string *hash, HashTable *nodes) { |
3115 | 3117 | redis_register_persistent_resource(cc->hash, cc, le_cluster_slot_cache); |
3116 | 3118 | } |
3117 | 3119 |
|
| 3120 | +void cluster_cache_clear(redisCluster *c) |
| 3121 | +{ |
| 3122 | + if (c->cache_key) { |
| 3123 | + zend_hash_del(&EG(persistent_list), c->cache_key); |
| 3124 | + } |
| 3125 | +} |
| 3126 | + |
3118 | 3127 |
|
3119 | 3128 | /* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */ |
Collapse file
Copy file name to clipboardExpand all lines: cluster_library.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -390,6 +390,7 @@ PHP_REDIS_API char **cluster_sock_read_multibulk_reply(RedisSock *redis_sock, in |
390 | 390 |
|
391 | 391 | PHP_REDIS_API void cluster_cache_store(zend_string *hash, HashTable *nodes); |
392 | 392 | PHP_REDIS_API redisCachedCluster *cluster_cache_load(zend_string *hash); |
| 393 | +void cluster_cache_clear(redisCluster *c); |
393 | 394 |
|
394 | 395 | /* |
395 | 396 | * Redis Cluster response handlers. Our response handlers generally take the |
|