Command info module API (#10108)
Adds RM_SetCommandInfo, allowing modules to provide the following command info:
* summary
* complexity
* since
* history
* hints
* arity
* key specs
* args
This information affects the output of `COMMAND`, `COMMAND INFO` and `COMMAND DOCS`,
Cluster, ACL and is used to filter commands with the wrong number of arguments before
the call reaches the module code.
The recently added API functions for key specs (never released) are removed.
A minimalist example would look like so:
```c
RedisModuleCommand *mycmd = RedisModule_GetCommand(ctx,"mymodule.mycommand");
RedisModuleCommandInfo mycmd_info = {
.version = REDISMODULE_COMMAND_INFO_VERSION,
.arity = -5,
.summary = "some description",
};
if (RedisModule_SetCommandInfo(mycmd, &mycmd_info) == REDISMODULE_ERR)
return REDISMODULE_ERR;
````
Notes:
* All the provided information (including strings) is copied, not keeping references to the API input data.
* The version field is actually a static struct that contains the sizes of the the structs used in arrays,
so we can extend these in the future and old version will still be able to take the part they can support.
2022-02-04 14:09:36 -05:00
|
|
|
set testmodule [file normalize tests/modules/cmdintrospection.so]
|
|
|
|
|
|
|
|
start_server {tags {"modules"}} {
|
|
|
|
r module load $testmodule
|
|
|
|
|
|
|
|
# cmdintrospection.xadd mimics XADD with regards to how
|
|
|
|
# what COMMAND exposes. There are two differences:
|
|
|
|
#
|
|
|
|
# 1. cmdintrospection.xadd (and all module commands) do not have ACL categories
|
|
|
|
# 2. cmdintrospection.xadd's `group` is "module"
|
|
|
|
#
|
|
|
|
# This tests verify that, apart from the above differences, the output of
|
|
|
|
# COMMAND INFO and COMMAND DOCS are identical for the two commands.
|
|
|
|
test "Module command introspection via COMMAND INFO" {
|
|
|
|
set redis_reply [lindex [r command info xadd] 0]
|
|
|
|
set module_reply [lindex [r command info cmdintrospection.xadd] 0]
|
|
|
|
for {set i 1} {$i < [llength $redis_reply]} {incr i} {
|
|
|
|
if {$i == 2} {
|
|
|
|
# Remove the "module" flag
|
|
|
|
set mylist [lindex $module_reply $i]
|
|
|
|
set idx [lsearch $mylist "module"]
|
|
|
|
set mylist [lreplace $mylist $idx $idx]
|
|
|
|
lset module_reply $i $mylist
|
|
|
|
}
|
|
|
|
if {$i == 6} {
|
|
|
|
# Skip ACL categories
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert_equal [lindex $redis_reply $i] [lindex $module_reply $i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test "Module command introspection via COMMAND DOCS" {
|
|
|
|
set redis_reply [dict create {*}[lindex [r command docs xadd] 1]]
|
|
|
|
set module_reply [dict create {*}[lindex [r command docs cmdintrospection.xadd] 1]]
|
|
|
|
# Compare the maps. We need to pop "group" first.
|
|
|
|
dict unset redis_reply group
|
|
|
|
dict unset module_reply group
|
2022-04-10 04:41:31 -04:00
|
|
|
dict unset module_reply module
|
Command info module API (#10108)
Adds RM_SetCommandInfo, allowing modules to provide the following command info:
* summary
* complexity
* since
* history
* hints
* arity
* key specs
* args
This information affects the output of `COMMAND`, `COMMAND INFO` and `COMMAND DOCS`,
Cluster, ACL and is used to filter commands with the wrong number of arguments before
the call reaches the module code.
The recently added API functions for key specs (never released) are removed.
A minimalist example would look like so:
```c
RedisModuleCommand *mycmd = RedisModule_GetCommand(ctx,"mymodule.mycommand");
RedisModuleCommandInfo mycmd_info = {
.version = REDISMODULE_COMMAND_INFO_VERSION,
.arity = -5,
.summary = "some description",
};
if (RedisModule_SetCommandInfo(mycmd, &mycmd_info) == REDISMODULE_ERR)
return REDISMODULE_ERR;
````
Notes:
* All the provided information (including strings) is copied, not keeping references to the API input data.
* The version field is actually a static struct that contains the sizes of the the structs used in arrays,
so we can extend these in the future and old version will still be able to take the part they can support.
2022-02-04 14:09:36 -05:00
|
|
|
|
|
|
|
assert_equal $redis_reply $module_reply
|
|
|
|
}
|
|
|
|
}
|