Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2019-08-11 06:48:50 +0300
committerMichael Grunder <michael.grunder@gmail.com>2019-08-27 22:05:58 +0300
commit0d6d3fdde34f48ae60c93968fae710ad70fa8c5a (patch)
tree92047700ac0229b91ae132f3c01e0c07c583ee47 /cluster_library.c
parent9c8f8e077e9d69d74957a3355d62900a3cbac7e8 (diff)
Also attach slaves when caching cluster slots
Addresses #1613
Diffstat (limited to 'cluster_library.c')
-rw-r--r--cluster_library.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/cluster_library.c b/cluster_library.c
index 64166cc6..6fc7328b 100644
--- a/cluster_library.c
+++ b/cluster_library.c
@@ -905,7 +905,7 @@ PHP_REDIS_API
redisCachedCluster *cluster_cache_create(zend_string *hash, HashTable *nodes) {
redisCachedCluster *cc;
redisCachedMaster *cm;
- redisClusterNode *node;
+ redisClusterNode *node, *slave;
cc = pecalloc(1, sizeof(*cc), 1);
cc->hash = zend_string_dup(hash, 1);
@@ -925,6 +925,19 @@ redisCachedCluster *cluster_cache_create(zend_string *hash, HashTable *nodes) {
/* Copy over slot ranges */
cm->slot = slot_range_list_clone(&node->slots, &cm->slots);
+ /* Attach any slave nodes we have. */
+ if (node->slaves) {
+ /* Allocate memory for slaves */
+ cm->slave = pemalloc(sizeof(*cm->slave) * zend_hash_num_elements(node->slaves), 1);
+
+ /* Copy host/port information for each slave */
+ ZEND_HASH_FOREACH_PTR(node->slaves, slave) {
+ cm->slave[cm->slaves].addr = zend_string_dup(slave->sock->host, 1);
+ cm->slave[cm->slaves].port = slave->sock->port;
+ cm->slaves++;
+ } ZEND_HASH_FOREACH_END();
+ }
+
cc->count++;
} ZEND_HASH_FOREACH_END();