Return a representable string of the node's slots */
| 2777 | |
| 2778 | /* Return a representable string of the node's slots */ |
| 2779 | static 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 | |
| 2808 | static sds clusterManagerNodeGetJSON(clusterManagerNode *node, |
| 2809 | unsigned long error_count) |
no test coverage detected