Module INFO, support default section for simple modules
This commit is contained in:
parent
d4c24a3067
commit
8319ffb34d
@ -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 "<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. */
|
||||
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)
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
|
@ -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}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user