diff --git a/src/module.c b/src/module.c index c48b2f045..046b9bc86 100644 --- a/src/module.c +++ b/src/module.c @@ -4709,9 +4709,12 @@ int RM_InfoEndDictField(RedisModuleInfoCtx *ctx); /* Used to start a new section, before adding any fields. the section name will * be prefixed by "_" and must only include A-Z,a-z,0-9. + * NULL or empty string indicates the default section (only ) is used. * When return value is REDISMODULE_ERR, the section should and will be skipped. */ int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) { - sds full_name = sdscatprintf(sdsdup(ctx->module->name), "_%s", name); + sds full_name = sdsdup(ctx->module->name); + if (name != NULL && strlen(name) > 0) + full_name = sdscatprintf(full_name, "_%s", name); /* Implicitly end dicts, instead of returning an error which is likely un checked. */ if (ctx->in_dict_field) diff --git a/tests/modules/infotest.c b/tests/modules/infotest.c index 1a75d1606..d28410932 100644 --- a/tests/modules/infotest.c +++ b/tests/modules/infotest.c @@ -3,6 +3,9 @@ #include void InfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) { + RedisModule_InfoAddSection(ctx, ""); + RedisModule_InfoAddFieldLongLong(ctx, "global", -2); + RedisModule_InfoAddSection(ctx, "Spanish"); RedisModule_InfoAddFieldCString(ctx, "uno", "one"); RedisModule_InfoAddFieldLongLong(ctx, "dos", 2); diff --git a/tests/unit/moduleapi/infotest.tcl b/tests/unit/moduleapi/infotest.tcl index 7f756f0e6..a64d729f3 100644 --- a/tests/unit/moduleapi/infotest.tcl +++ b/tests/unit/moduleapi/infotest.tcl @@ -14,12 +14,14 @@ start_server {tags {"modules"}} { set info [r info all] # info all does not contain modules assert { ![string match "*Spanish*" $info] } + assert { ![string match "*infotest*" $info] } assert { [string match "*used_memory*" $info] } } test {module info everything} { set info [r info everything] # info everything contains all default sections, but not ones for crash report + assert { [string match "*infotest_global*" $info] } assert { [string match "*Spanish*" $info] } assert { [string match "*Italian*" $info] } assert { [string match "*used_memory*" $info] } @@ -31,6 +33,7 @@ start_server {tags {"modules"}} { set info [r info modules] # info all does not contain modules assert { [string match "*Spanish*" $info] } + assert { [string match "*infotest_global*" $info] } assert { ![string match "*used_memory*" $info] } } @@ -39,12 +42,14 @@ start_server {tags {"modules"}} { # info all does not contain modules assert { [string match "*Spanish*" $info] } assert { ![string match "*used_memory*" $info] } - } + field $info infotest_global + } {-2} test {module info one section} { set info [r info INFOTEST_SPANISH] assert { ![string match "*used_memory*" $info] } assert { ![string match "*Italian*" $info] } + assert { ![string match "*infotest_global*" $info] } field $info infotest_uno } {one}