mirror of
https://github.com/fluencelabs/redis
synced 2025-06-28 00:11:33 +00:00
Merge pull request #6270 from oranagra/modules_info
Extend modules API to allow modules report to redis INFO
This commit is contained in:
@ -13,7 +13,7 @@ endif
|
||||
|
||||
.SUFFIXES: .c .so .xo .o
|
||||
|
||||
all: commandfilter.so testrdb.so fork.so
|
||||
all: commandfilter.so testrdb.so fork.so infotest.so
|
||||
|
||||
.c.xo:
|
||||
$(CC) -I../../src $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@
|
||||
@ -21,6 +21,7 @@ all: commandfilter.so testrdb.so fork.so
|
||||
commandfilter.xo: ../../src/redismodule.h
|
||||
fork.xo: ../../src/redismodule.h
|
||||
testrdb.xo: ../../src/redismodule.h
|
||||
infotest.xo: ../../src/redismodule.h
|
||||
|
||||
commandfilter.so: commandfilter.xo
|
||||
$(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
@ -30,3 +31,7 @@ fork.so: fork.xo
|
||||
|
||||
testrdb.so: testrdb.xo
|
||||
$(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
infotest.so: infotest.xo
|
||||
$(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
|
41
tests/modules/infotest.c
Normal file
41
tests/modules/infotest.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include "redismodule.h"
|
||||
|
||||
#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);
|
||||
|
||||
RedisModule_InfoAddSection(ctx, "Italian");
|
||||
RedisModule_InfoAddFieldLongLong(ctx, "due", 2);
|
||||
RedisModule_InfoAddFieldDouble(ctx, "tre", 3.3);
|
||||
|
||||
RedisModule_InfoAddSection(ctx, "keyspace");
|
||||
RedisModule_InfoBeginDictField(ctx, "db0");
|
||||
RedisModule_InfoAddFieldLongLong(ctx, "keys", 3);
|
||||
RedisModule_InfoAddFieldLongLong(ctx, "expires", 1);
|
||||
RedisModule_InfoEndDictField(ctx);
|
||||
|
||||
if (for_crash_report) {
|
||||
RedisModule_InfoAddSection(ctx, "Klingon");
|
||||
RedisModule_InfoAddFieldCString(ctx, "one", "wa’");
|
||||
RedisModule_InfoAddFieldCString(ctx, "two", "cha’");
|
||||
RedisModule_InfoAddFieldCString(ctx, "three", "wej");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
if (RedisModule_Init(ctx,"infotest",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
|
||||
if (RedisModule_RegisterInfoFunc(ctx, InfoFunc) == REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
}
|
63
tests/unit/moduleapi/infotest.tcl
Normal file
63
tests/unit/moduleapi/infotest.tcl
Normal file
@ -0,0 +1,63 @@
|
||||
set testmodule [file normalize tests/modules/infotest.so]
|
||||
|
||||
# Return value for INFO property
|
||||
proc field {info property} {
|
||||
if {[regexp "\r\n$property:(.*?)\r\n" $info _ value]} {
|
||||
set _ $value
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule log-key 0
|
||||
|
||||
test {module info all} {
|
||||
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] }
|
||||
assert { ![string match "*Klingon*" $info] }
|
||||
field $info infotest_dos
|
||||
} {2}
|
||||
|
||||
test {module info 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] }
|
||||
}
|
||||
|
||||
test {module info one module} {
|
||||
set info [r info INFOTEST]
|
||||
# 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}
|
||||
|
||||
test {module info dict} {
|
||||
set info [r info infotest_keyspace]
|
||||
set keyspace [field $info infotest_db0]
|
||||
set keys [scan [regexp -inline {keys\=([\d]*)} $keyspace] keys=%d]
|
||||
} {3}
|
||||
|
||||
# TODO: test crash report.
|
||||
}
|
Reference in New Issue
Block a user