Skip to content

Commit

Permalink
Minor revision
Browse files Browse the repository at this point in the history
- Updated the RESP3 response from array of maps to array of arrays.

Signed-off-by: Kyle Kim <[email protected]>
  • Loading branch information
kyle-yh-kim committed Jun 27, 2024
1 parent 12730f0 commit 6921c02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/cluster_slot_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ static void collectAndSortSlotStats(slotStatForSort slot_stats[], int order_by,
}

static void addReplySlotStat(client *c, int slot) {
addReplyMapLen(c, 1); /* Map for (int) slot to (map) usage statistics. */
addReplyArrayLen(c, 2); /* Array of size 2, where 0th index represents (int) slot,
* and 1st index represents (map) usage statistics. */
addReplyLongLong(c, slot);
addReplyMapLen(c, 1); /* Nested map representing slot usage statistics. */
addReplyBulkCString(c, "key-count");
Expand Down
14 changes: 9 additions & 5 deletions src/commands/cluster-slot-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
],
"reply_schema": {
"type": "array",
"description": "Array of nested maps, where each map represents a slot and its respective usage statistics.",
"description": "Array of nested arrays, where the inner array element represents a slot and its respective usage statistics.",
"items": {
"type": "object",
"description": "Map of a slot and its respective usage statistics.",
"additionalProperties": {
"type": "string"
"type": "array",
"description": "Array of size 2, where 0th index represents (int) slot, and 1st index represents (map) usage statistics.",
"items": {
"type": "object",
"description": "Map of slot usage statistics.",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/cluster/slot-stats.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
proc convert_array_into_dict {slot_stats} {
set res [dict create]
foreach slot_stat $slot_stats {
# slot_stat is a map of (int) slot to (map) usage statistics.
dict for {slot stat} $slot_stat {
dict set res $slot $stat
}
# slot_stat is an array of size 2, where 0th index represents (int) slot,
# and 1st index represents (map) usage statistics.
dict set res [lindex $slot_stat 0] [lindex $slot_stat 1]
}
return $res
}
Expand Down

0 comments on commit 6921c02

Please sign in to comment.