MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterManagerNodeSlotsString

Function clusterManagerNodeSlotsString

app/redis-6.2.6/src/redis-cli.c:3168–3195  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3166
3167/* Return a representable string of the node's slots */
3168static 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
3197static sds clusterManagerNodeGetJSON(clusterManagerNode *node,
3198 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