Return a representable string of the node's slots */
| 3166 | |
| 3167 | /* Return a representable string of the node's slots */ |
| 3168 | static sds clusterManagerNodeSlotsString(clusterManagerNode *node) { |
| 3169 | sds slots = sdsempty(); |
| 3170 | int first_range_idx = -1, last_slot_idx = -1, i; |
| 3171 | for (i = 0; i < CLUSTER_MANAGER_SLOTS; i++) { |
| 3172 | int has_slot = node->slots[i]; |
| 3173 | if (has_slot) { |
| 3174 | if (first_range_idx == -1) { |
| 3175 | if (sdslen(slots)) slots = sdscat(slots, ","); |
| 3176 | first_range_idx = i; |
| 3177 | slots = sdscatfmt(slots, "[%u", i); |
| 3178 | } |
| 3179 | last_slot_idx = i; |
| 3180 | } else { |
| 3181 | if (last_slot_idx >= 0) { |
| 3182 | if (first_range_idx == last_slot_idx) |
| 3183 | slots = sdscat(slots, "]"); |
| 3184 | else slots = sdscatfmt(slots, "-%u]", last_slot_idx); |
| 3185 | } |
| 3186 | last_slot_idx = -1; |
| 3187 | first_range_idx = -1; |
| 3188 | } |
| 3189 | } |
| 3190 | if (last_slot_idx >= 0) { |
| 3191 | if (first_range_idx == last_slot_idx) slots = sdscat(slots, "]"); |
| 3192 | else slots = sdscatfmt(slots, "-%u]", last_slot_idx); |
| 3193 | } |
| 3194 | return slots; |
| 3195 | } |
| 3196 | |
| 3197 | static sds clusterManagerNodeGetJSON(clusterManagerNode *node, |
| 3198 | unsigned long error_count) |
no test coverage detected