Module INFO, support default section for simple modules

This commit is contained in:
Oran Agra 2019-08-18 10:01:57 +03:00
parent d4c24a3067
commit 8319ffb34d
3 changed files with 13 additions and 2 deletions

View File

@ -4709,9 +4709,12 @@ int RM_InfoEndDictField(RedisModuleInfoCtx *ctx);
/* Used to start a new section, before adding any fields. the section name will /* Used to start a new section, before adding any fields. the section name will
* be prefixed by "<modulename>_" and must only include A-Z,a-z,0-9. * be prefixed by "<modulename>_" and must only include A-Z,a-z,0-9.
* NULL or empty string indicates the default section (only <modulename>) is used.
* When return value is REDISMODULE_ERR, the section should and will be skipped. */ * When return value is REDISMODULE_ERR, the section should and will be skipped. */
int RM_InfoAddSection(RedisModuleInfoCtx *ctx, char *name) { 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. */ /* Implicitly end dicts, instead of returning an error which is likely un checked. */
if (ctx->in_dict_field) if (ctx->in_dict_field)

View File

@ -3,6 +3,9 @@
#include <string.h> #include <string.h>
void InfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) { void InfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) {
RedisModule_InfoAddSection(ctx, "");
RedisModule_InfoAddFieldLongLong(ctx, "global", -2);
RedisModule_InfoAddSection(ctx, "Spanish"); RedisModule_InfoAddSection(ctx, "Spanish");
RedisModule_InfoAddFieldCString(ctx, "uno", "one"); RedisModule_InfoAddFieldCString(ctx, "uno", "one");
RedisModule_InfoAddFieldLongLong(ctx, "dos", 2); RedisModule_InfoAddFieldLongLong(ctx, "dos", 2);

View File

@ -14,12 +14,14 @@ start_server {tags {"modules"}} {
set info [r info all] set info [r info all]
# info all does not contain modules # info all does not contain modules
assert { ![string match "*Spanish*" $info] } assert { ![string match "*Spanish*" $info] }
assert { ![string match "*infotest*" $info] }
assert { [string match "*used_memory*" $info] } assert { [string match "*used_memory*" $info] }
} }
test {module info everything} { test {module info everything} {
set info [r info everything] set info [r info everything]
# info everything contains all default sections, but not ones for crash report # 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 "*Spanish*" $info] }
assert { [string match "*Italian*" $info] } assert { [string match "*Italian*" $info] }
assert { [string match "*used_memory*" $info] } assert { [string match "*used_memory*" $info] }
@ -31,6 +33,7 @@ start_server {tags {"modules"}} {
set info [r info modules] set info [r info modules]
# info all does not contain modules # info all does not contain modules
assert { [string match "*Spanish*" $info] } assert { [string match "*Spanish*" $info] }
assert { [string match "*infotest_global*" $info] }
assert { ![string match "*used_memory*" $info] } assert { ![string match "*used_memory*" $info] }
} }
@ -39,12 +42,14 @@ start_server {tags {"modules"}} {
# info all does not contain modules # info all does not contain modules
assert { [string match "*Spanish*" $info] } assert { [string match "*Spanish*" $info] }
assert { ![string match "*used_memory*" $info] } assert { ![string match "*used_memory*" $info] }
} field $info infotest_global
} {-2}
test {module info one section} { test {module info one section} {
set info [r info INFOTEST_SPANISH] set info [r info INFOTEST_SPANISH]
assert { ![string match "*used_memory*" $info] } assert { ![string match "*used_memory*" $info] }
assert { ![string match "*Italian*" $info] } assert { ![string match "*Italian*" $info] }
assert { ![string match "*infotest_global*" $info] }
field $info infotest_uno field $info infotest_uno
} {one} } {one}