diff options
author | yanhui13 <yanhui13@meituan.com> | 2020-04-21 16:55:05 +0800 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2020-04-23 16:19:56 +0200 |
commit | 7a62eb96ef31dd36b78274f4c921799fc0588be3 (patch) | |
tree | f6064c26ec99b3199a71ed8b5941a244886041d8 | |
parent | 0efb93d0c00b20ca87b18a92484225a54614aef6 (diff) | |
download | redis-7a62eb96ef31dd36b78274f4c921799fc0588be3.tar.gz |
optimize the output of cluster slots
-rw-r--r-- | src/cluster.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/cluster.c b/src/cluster.c index 02b6c2cfd..78d7290c4 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -4148,11 +4148,17 @@ void clusterReplyMultiBulkSlots(client *c) { while((de = dictNext(di)) != NULL) { clusterNode *node = dictGetVal(de); int j = 0, start = -1; + int i, nested_elements = 0; /* Skip slaves (that are iterated when producing the output of their * master) and masters not serving any slot. */ if (!nodeIsMaster(node) || node->numslots == 0) continue; + for(i = 0; i < node->numslaves; i++) { + if (nodeFailed(node->slaves[i])) continue; + nested_elements++; + } + for (j = 0; j < CLUSTER_SLOTS; j++) { int bit, i; @@ -4160,8 +4166,7 @@ void clusterReplyMultiBulkSlots(client *c) { if (start == -1) start = j; } if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) { - int nested_elements = 3; /* slots (2) + master addr (1). */ - void *nested_replylen = addDeferredMultiBulkLength(c); + addReplyMultiBulkLen(c, nested_elements + 3); /* slots (2) + master addr (1). */ if (bit && j == CLUSTER_SLOTS-1) j++; @@ -4191,9 +4196,7 @@ void clusterReplyMultiBulkSlots(client *c) { addReplyBulkCString(c, node->slaves[i]->ip); addReplyLongLong(c, node->slaves[i]->port); addReplyBulkCBuffer(c, node->slaves[i]->name, CLUSTER_NAMELEN); - nested_elements++; } - setDeferredMultiBulkLength(c, nested_replylen, nested_elements); num_masters++; } } |