Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
61853ad8
Commit
61853ad8
authored
Aug 18, 2019
by
Oran Agra
Browse files
Module INFO, support default section for simple modules
parent
1d6e5dc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
61853ad8
...
...
@@ -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
)
...
...
tests/modules/infotest.c
View file @
61853ad8
...
...
@@ -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
);
...
...
tests/unit/moduleapi/infotest.tcl
View file @
61853ad8
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment