redis-cli: Fix print of keys per cluster host when over int max (#11698)

When running cluster info, and the number of keys overflows the integer
value, the summary no longer makes sense. This fixes by using an appropriate
type to handle values over the max int value.
This commit is contained in:
Tyler Bream (Event pipeline) 2023-08-16 03:48:49 -04:00 committed by GitHub
parent 17904780ae
commit ac6bc5d1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4577,7 +4577,7 @@ static void clusterManagerShowNodes(void) {
static void clusterManagerShowClusterInfo(void) { static void clusterManagerShowClusterInfo(void) {
int masters = 0; int masters = 0;
int keys = 0; long long keys = 0;
listIter li; listIter li;
listNode *ln; listNode *ln;
listRewind(cluster_manager.nodes, &li); listRewind(cluster_manager.nodes, &li);
@ -4586,7 +4586,7 @@ static void clusterManagerShowClusterInfo(void) {
if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) { if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) {
if (!node->name) continue; if (!node->name) continue;
int replicas = 0; int replicas = 0;
int dbsize = -1; long long dbsize = -1;
char name[9]; char name[9];
memcpy(name, node->name, 8); memcpy(name, node->name, 8);
name[8] = '\0'; name[8] = '\0';
@ -4612,14 +4612,14 @@ static void clusterManagerShowClusterInfo(void) {
return; return;
}; };
if (reply != NULL) freeReplyObject(reply); if (reply != NULL) freeReplyObject(reply);
printf("%s:%d (%s...) -> %d keys | %d slots | %d slaves.\n", printf("%s:%d (%s...) -> %lld keys | %d slots | %d slaves.\n",
node->ip, node->port, name, dbsize, node->ip, node->port, name, dbsize,
node->slots_count, replicas); node->slots_count, replicas);
masters++; masters++;
keys += dbsize; keys += dbsize;
} }
} }
clusterManagerLogOk("[OK] %d keys in %d masters.\n", keys, masters); clusterManagerLogOk("[OK] %lld keys in %d masters.\n", keys, masters);
float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS; float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS;
printf("%.2f keys per slot on average.\n", keys_per_slot); printf("%.2f keys per slot on average.\n", keys_per_slot);
} }