COMMAND DOCS shows module name, where applicable (#10544)

Add field to COMMAND DOCS response to denote the name of the module
that added that command.
COMMAND LIST can filter by module, but if you get the full commands list,
you may still wanna know which command belongs to which module.
The alternative would be to do MODULE LIST, and then multiple calls to COMMAND LIST
This commit is contained in:
guybe7 2022-04-10 10:41:31 +02:00 committed by GitHub
parent 6cb5cbb28f
commit 719db14ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 2 deletions

View File

@ -6082,6 +6082,14 @@ const char *moduleTypeModuleName(moduleType *mt) {
return mt->module->name; return mt->module->name;
} }
/* Return the module name from a module command */
const char *moduleNameFromCommand(struct redisCommand *cmd) {
serverAssert(cmd->proc == RedisModuleCommandDispatcher);
RedisModuleCommand *cp = (void*)(unsigned long)cmd->getkeys_proc;
return cp->module->name;
}
/* Create a copy of a module type value using the copy callback. If failed /* Create a copy of a module type value using the copy callback. If failed
* or not supported, produce an error reply and return NULL. * or not supported, produce an error reply and return NULL.
*/ */

View File

@ -4562,6 +4562,7 @@ void addReplyCommandDocs(client *c, struct redisCommand *cmd) {
long maplen = 1; long maplen = 1;
if (cmd->summary) maplen++; if (cmd->summary) maplen++;
if (cmd->since) maplen++; if (cmd->since) maplen++;
if (cmd->flags & CMD_MODULE) maplen++;
if (cmd->complexity) maplen++; if (cmd->complexity) maplen++;
if (cmd->doc_flags) maplen++; if (cmd->doc_flags) maplen++;
if (cmd->deprecated_since) maplen++; if (cmd->deprecated_since) maplen++;
@ -4588,6 +4589,10 @@ void addReplyCommandDocs(client *c, struct redisCommand *cmd) {
addReplyBulkCString(c, "complexity"); addReplyBulkCString(c, "complexity");
addReplyBulkCString(c, cmd->complexity); addReplyBulkCString(c, cmd->complexity);
} }
if (cmd->flags & CMD_MODULE) {
addReplyBulkCString(c, "module");
addReplyBulkCString(c, moduleNameFromCommand(cmd));
}
if (cmd->doc_flags) { if (cmd->doc_flags) {
addReplyBulkCString(c, "doc_flags"); addReplyBulkCString(c, "doc_flags");
addReplyDocFlagsForCommand(c, cmd); addReplyDocFlagsForCommand(c, cmd);

View File

@ -2349,6 +2349,7 @@ int moduleGetCommandChannelsViaAPI(struct redisCommand *cmd, robj **argv, int ar
moduleType *moduleTypeLookupModuleByID(uint64_t id); moduleType *moduleTypeLookupModuleByID(uint64_t id);
void moduleTypeNameByID(char *name, uint64_t moduleid); void moduleTypeNameByID(char *name, uint64_t moduleid);
const char *moduleTypeModuleName(moduleType *mt); const char *moduleTypeModuleName(moduleType *mt);
const char *moduleNameFromCommand(struct redisCommand *cmd);
void moduleFreeContext(struct RedisModuleCtx *ctx); void moduleFreeContext(struct RedisModuleCtx *ctx);
void unblockClientFromModule(client *c); void unblockClientFromModule(client *c);
void moduleHandleBlockedClients(void); void moduleHandleBlockedClients(void);

View File

@ -36,6 +36,7 @@ start_server {tags {"modules"}} {
# Compare the maps. We need to pop "group" first. # Compare the maps. We need to pop "group" first.
dict unset redis_reply group dict unset redis_reply group
dict unset module_reply group dict unset module_reply group
dict unset module_reply module
assert_equal $redis_reply $module_reply assert_equal $redis_reply $module_reply
} }

View File

@ -15,8 +15,8 @@ start_server {tags {"modules"}} {
set docs_reply [r command docs subcommands.bitarray] set docs_reply [r command docs subcommands.bitarray]
set docs [dict create {*}[lindex $docs_reply 1]] set docs [dict create {*}[lindex $docs_reply 1]]
set subcmds_in_cmd_docs [dict create {*}[dict get $docs subcommands]] set subcmds_in_cmd_docs [dict create {*}[dict get $docs subcommands]]
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|get"] {group module} assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|get"] {group module module subcommands}
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|set"] {group module} assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|set"] {group module module subcommands}
} }
test "Module pure-container command fails on arity error" { test "Module pure-container command fails on arity error" {