redis/tests/modules
Mincho Paskalev 15706f2e82
Module set/get config API (#14051)
# Problem

Some redis modules need to call `CONFIG GET/SET` commands. Server may be
ran with `rename-command CONFIG ""`(or something similar) which leads to
the module being unable to access the config.

# Solution

Added new API functions for use by modules
```
RedisModuleConfigIterator* RedisModule_GetConfigIterator(RedisModuleCtx *ctx, const char *pattern);
void RedisModule_ReleaseConfigIterator(RedisModuleCtx *ctx, RedisModuleConfigIterator *iter);
const char *RedisModule_ConfigIteratorNext(RedisModuleConfigIterator *iter);
int RedisModule_GetConfigType(const char *name, RedisModuleConfigType *res);
int RedisModule_GetBoolConfig(RedisModuleCtx *ctx, const char *name, int *res);
int RedisModule_GetConfig(RedisModuleCtx *ctx, const char *name, RedisModuleString **res);
int RedisModule_GetEnumConfig(RedisModuleCtx *ctx, const char *name, RedisModuleString **res);
int RedisModule_GetNumericConfig(RedisModuleCtx *ctx, const char *name, long long *res);
int RedisModule_SetBoolConfig(RedisModuleCtx *ctx, const char *name, int value, RedisModuleString **err);
int RedisModule_SetConfig(RedisModuleCtx *ctx, const char *name, RedisModuleString *value, RedisModuleString **err);
int RedisModule_SetEnumConfig(RedisModuleCtx *ctx, const char *name, RedisModuleString *value, RedisModuleString **err);
int RedisModule_SetNumericConfig(RedisModuleCtx *ctx, const char *name, long long value, RedisModuleString **err);
```

## Implementation

The work is mostly done inside `config.c` as I didn't want to expose the
config dict outside of it. That means each of these module functions has
a corresponding method in `config.c` that actually does the job. F.e
`RedisModule_SetEnumConfig` calls `moduleSetEnumConfig` which is
implemented in `config.c`

## Notes

Also, refactored `configSetCommand` and `restoreBackupConfig` functions
for the following reasons:
- code and logic is now way more clear in `configSetCommand`. Only
caveat here is removal of an optimization that skipped running apply
functions that already have ran in favour of code clarity.
- Both functions needlessly separated logic for module configs and
normal configs whereas no such separation is needed. This also had the
side effect of removing some allocations.
- `restoreBackupConfig` now has clearer interface and can be reused with
ease. One of the places I reused it is for the individual
`moduleSet*Config` functions, each of which needs the restoration
functionality but for a single config only.

## Future

Additionally, a couple considerations were made for potentially
extending the API in the future
- if need be an API for atomically setting multiple config values can be
added - `RedisModule_SetConfigsTranscationStart/End` or similar that can
be put around `RedisModule_Set*Config` calls.
- if performance is an issue an API
`RedisModule_GetConfigIteratorNextWithTypehint` or similar may be added
in order not to incur the additional cost of calling
`RedisModule_GetConfigType`.

---------

Co-authored-by: Oran Agra <oran@redislabs.com>
2025-07-03 13:46:33 +03:00
..
Makefile Module set/get config API (#14051) 2025-07-03 13:46:33 +03:00
aclcheck.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
auth.c Fix daylight race condition and some thread leaks (#13191) 2024-04-04 13:49:51 +03:00
basics.c Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
blockedclient.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
blockonbackground.c Fix daylight race condition and some thread leaks (#13191) 2024-04-04 13:49:51 +03:00
blockonkeys.c Modules: Unblock from within a timer coverage (#12337) 2023-06-22 23:15:16 +03:00
cmdintrospection.c Add XDELEX and XACKDEL commands for stream (#14130) 2025-07-01 21:00:42 +08:00
commandfilter.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
configaccess.c Module set/get config API (#14051) 2025-07-03 13:46:33 +03:00
crash.c Print command tokens on a crash when hide-user-data-from-log is enabled (#13639) 2024-11-11 09:34:18 +03:00
datatype.c Fix module loadex command crash due to invalid config (#13653) 2024-11-21 14:14:14 +08:00
datatype2.c Use const char pointer in redismodule.h as far as possible (#10064) 2022-01-18 15:55:20 +02:00
defragtest.c Make RM_DefragRedisModuleDict API support incremental defragmentation for dict leaf (#13840) 2025-03-04 17:19:41 +08:00
eventloop.c delete obsolete REDISMODULE_EXPERIMENTAL_API define in module demos (#10527) 2022-04-05 08:21:41 +03:00
fork.c Fix race in module fork kill test (#10717) 2022-05-12 20:10:38 +03:00
getchannels.c Implemented module getchannels api and renamed channel keyspec (#10299) 2022-02-22 11:00:03 +02:00
getkeys.c Handle key-spec flags with modules (#10237) 2022-02-08 10:01:35 +02:00
hash.c Modules API: new HashFieldMinExpire(). Add flag REDISMODULE_HASH_EXPIRE_TIME to HashGet(). (#13676) 2024-12-05 11:14:52 +02:00
hooks.c Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
infotest.c Update supported version list. (#12488) 2023-08-16 08:36:40 +03:00
internalsecret.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
keyspace_events.c Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
keyspecs.c RM_CreateCommand should not set CMD_KEY_VARIABLE_FLAGS automatically (#11320) 2022-09-28 14:15:07 +03:00
list.c Fix crash due to to reuse iterator entry after list deletion in module (#11383) 2022-10-22 20:36:50 +03:00
mallocsize.c Add RM_MallocSizeString, RM_MallocSizeDict (#10542) 2022-04-17 08:31:57 +03:00
misc.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
moduleauthtwo.c Custom authentication for Modules (#11659) 2023-03-15 15:18:42 -07:00
moduleconfigs.c Update tests/modules/moduleconfigs.c 2025-02-06 13:16:33 +02:00
moduleconfigstwo.c Module Configurations (#10285) 2022-03-30 15:47:06 +03:00
postnotifications.c Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
propagate.c Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
publish.c Fix broken protocol when PUBLISH emits local push inside MULTI (#12326) 2023-06-20 20:41:41 +03:00
rdbloadsave.c Add RM_RdbLoad and RM_RdbSave module API functions (#11852) 2023-04-09 12:07:32 +03:00
reply.c Add RM_ReplyWithErrorFormat that can support format (#11923) 2023-04-12 10:11:29 +03:00
scan.c Replace deprecated REDISMODULE_POSTPONED_ARRAY_LEN in module tests and examples (#9677) 2021-10-25 12:00:43 +03:00
stream.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00
subcommands.c Block some specific characters in module command names (#11434) 2022-11-03 13:19:49 +02:00
test_lazyfree.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00
testrdb.c Avoid saving module aux on RDB if no aux data was saved by the module. (#11374) 2022-10-18 19:45:46 +03:00
timer.c Modules: Mark all APIs non-experimental (#9983) 2021-12-30 12:17:22 +02:00
usercall.c Add size_t cast for RM_call() in module tests (#14061) 2025-05-23 10:10:11 +08:00
zset.c Delete empty key if fails after moduleCreateEmptyKey() in module (#12129) 2023-05-07 10:13:19 +03:00