MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerNodeSlotsString

Function clusterManagerNodeSlotsString

src/redis-cli.c:2779–2806  ·  view source on GitHub ↗

Return a representable string of the node's slots */

Source from the content-addressed store, hash-verified

2777
2778/* Return a representable string of the node's slots */
2779static sds clusterManagerNodeSlotsString(clusterManagerNode *node) {
2780 sds slots = sdsempty();
2781 int first_range_idx = -1, last_slot_idx = -1, i;
2782 for (i = 0; i < CLUSTER_MANAGER_SLOTS; i++) {
2783 int has_slot = node->slots[i];
2784 if (has_slot) {
2785 if (first_range_idx == -1) {
2786 if (sdslen(slots)) slots = sdscat(slots, ",");
2787 first_range_idx = i;
2788 slots = sdscatfmt(slots, "[%u", i);
2789 }
2790 last_slot_idx = i;
2791 } else {
2792 if (last_slot_idx >= 0) {
2793 if (first_range_idx == last_slot_idx)
2794 slots = sdscat(slots, "]");
2795 else slots = sdscatfmt(slots, "-%u]", last_slot_idx);
2796 }
2797 last_slot_idx = -1;
2798 first_range_idx = -1;
2799 }
2800 }
2801 if (last_slot_idx >= 0) {
2802 if (first_range_idx == last_slot_idx) slots = sdscat(slots, "]");
2803 else slots = sdscatfmt(slots, "-%u]", last_slot_idx);
2804 }
2805 return slots;
2806}
2807
2808static sds clusterManagerNodeGetJSON(clusterManagerNode *node,
2809 unsigned long error_count)

Callers 3

clusterManagerNodeInfoFunction · 0.85

Calls 4

sdsemptyFunction · 0.85
sdslenFunction · 0.85
sdscatFunction · 0.85
sdscatfmtFunction · 0.85

Tested by

no test coverage detected