Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <[email protected]>
  • Loading branch information
hwware committed Oct 22, 2024
1 parent 285064b commit 5f0cd78
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/commands/module-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
"items": {
"type": "string"
}
},
"configs": {
"type": "array",
"description": "Module configs.",
"items": {
"type": "string"
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,21 @@ static void numericConfigRewrite(standardConfig *config, const char *name, struc
}
}

sds getConfigValue(sds config_name) {
standardConfig *config = lookupConfig(config_name);
switch (config->type) {
case BOOL_CONFIG:
return boolConfigGet(config);
case SDS_CONFIG:
return sdsConfigGet(config);
case NUMERIC_CONFIG:
return numericConfigGet(config);
case ENUM_CONFIG:
return enumConfigGet(config);
default: serverPanic("Config type of module config is not allowed.");
}
}

#define embedCommonNumericalConfig(name, alias, _flags, lower, upper, config_addr, default, num_conf_flags, is_valid, \
apply) \
{ \
Expand Down
16 changes: 15 additions & 1 deletion src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -12356,7 +12356,7 @@ void addReplyLoadedModules(client *c) {
sds name = dictGetKey(de);
struct ValkeyModule *module = dictGetVal(de);
sds path = module->loadmod->path;
addReplyMapLen(c, 4);
addReplyMapLen(c, 5);
addReplyBulkCString(c, "name");
addReplyBulkCBuffer(c, name, sdslen(name));
addReplyBulkCString(c, "ver");
Expand All @@ -12368,6 +12368,20 @@ void addReplyLoadedModules(client *c) {
for (int i = 0; i < module->loadmod->argc; i++) {
addReplyBulk(c, module->loadmod->argv[i]);
}
addReplyBulkCString(c, "configs");
addReplyArrayLen(c, listLength(module->module_configs) * 2);
listIter li;
listNode *ln;
listRewind(module->module_configs, &li);
while ((ln = listNext(&li))) {
ModuleConfig *module_config = listNodeValue(ln);
sds config_name = sdscatfmt(sdsempty(), "%s.%s", module->name, module_config->name);
addReplyBulkCBuffer(c, config_name, sdslen(config_name));
sds config_value = getConfigValue(config_name);
addReplyBulkCBuffer(c, config_value, sdslen(config_value));
sdsfree(config_name);
sdsfree(config_value);
}
}
dictReleaseIterator(di);
}
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,7 @@ void freeServerClientMemUsageBuckets(void);

/* Module Configuration */
typedef struct ModuleConfig ModuleConfig;
sds getConfigValue(sds config_name);
int performModuleConfigSetFromName(sds name, sds value, const char **err);
int performModuleConfigSetDefaultFromName(sds name, const char **err);
void addModuleBoolConfig(const char *module_name, const char *name, int flags, void *privdata, int default_val);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/moduleapi/moduleconfigs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ start_server {tags {"modules"}} {
assert_equal [r config get moduleconfigs.numeric] "moduleconfigs.numeric -1"
}

test {check config value output correctly from module list} {
set config_value [lindex [lmap x [r module list] {dict get $x configs}] 0]
assert_equal [lindex $config_value 0] "moduleconfigs.mutable_bool"
assert_equal [lindex $config_value 1] "yes"
assert_equal [lindex $config_value 2] "moduleconfigs.immutable_bool"
assert_equal [lindex $config_value 3] "no"
assert_equal [lindex $config_value 4] "moduleconfigs.string"
assert_equal [lindex $config_value 5] "secret password"
}

test {Config set commands work} {
# Make sure that config sets work during runtime
r config set moduleconfigs.mutable_bool no
Expand Down

0 comments on commit 5f0cd78

Please sign in to comment.