support whole cluster info for INFO command in cluster section (#2876)

Allow users to more easily get cluster information.

Signed-off-by: zhaozhao.zz <zhaozhao.zz@alibaba-inc.com>
This commit is contained in:
zhaozhao.zz 2025-12-05 01:34:52 +08:00 committed by GitHub
parent 3d65a4aecd
commit 04d0bba398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 5 additions and 5 deletions

View File

@ -898,7 +898,7 @@ void clusterCommand(client *c) {
} else if (!strcasecmp(c->argv[1]->ptr, "info") && c->argc == 2) { } else if (!strcasecmp(c->argv[1]->ptr, "info") && c->argc == 2) {
/* CLUSTER INFO */ /* CLUSTER INFO */
sds info = genClusterInfoString(); sds info = genClusterInfoString(sdsempty());
/* Produce the reply protocol. */ /* Produce the reply protocol. */
addReplyVerbatim(c, info, sdslen(info), "txt"); addReplyVerbatim(c, info, sdslen(info), "txt");

View File

@ -75,7 +75,7 @@ unsigned long getClusterConnectionsCount(void);
int isClusterHealthy(void); int isClusterHealthy(void);
sds clusterGenNodesDescription(client *c, int filter, int tls_primary); sds clusterGenNodesDescription(client *c, int filter, int tls_primary);
sds genClusterInfoString(void); sds genClusterInfoString(sds info);
/* handle implementation specific debug cluster commands. Return 1 if handled, 0 otherwise. */ /* handle implementation specific debug cluster commands. Return 1 if handled, 0 otherwise. */
int handleDebugClusterCommand(client *c); int handleDebugClusterCommand(client *c);
const char **clusterDebugCommandExtendedHelp(void); const char **clusterDebugCommandExtendedHelp(void);

View File

@ -7041,8 +7041,7 @@ void clusterCommandShards(client *c) {
dictReleaseIterator(di); dictReleaseIterator(di);
} }
sds genClusterInfoString(void) { sds genClusterInfoString(sds info) {
sds info = sdsempty();
char *statestr[] = {"ok", "fail"}; char *statestr[] = {"ok", "fail"};
int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0; int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0;

View File

@ -1862,7 +1862,7 @@ __attribute__((noinline)) void logStackTrace(void *eip, int uplevel, int current
#endif /* HAVE_BACKTRACE */ #endif /* HAVE_BACKTRACE */
sds genClusterDebugString(sds infostring) { sds genClusterDebugString(sds infostring) {
sds cluster_info = genClusterInfoString(); sds cluster_info = genClusterInfoString(sdsempty());
sds cluster_nodes = clusterGenNodesDescription(NULL, 0, 0); sds cluster_nodes = clusterGenNodesDescription(NULL, 0, 0);
infostring = sdscatprintf(infostring, "\r\n# Cluster info\r\n"); infostring = sdscatprintf(infostring, "\r\n# Cluster info\r\n");

View File

@ -6433,6 +6433,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
"# Cluster\r\n" "# Cluster\r\n"
"cluster_enabled:%d\r\n", "cluster_enabled:%d\r\n",
server.cluster_enabled); server.cluster_enabled);
if (server.cluster_enabled) info = genClusterInfoString(info);
} }
/* Scripting engines */ /* Scripting engines */