redis/tests/unit
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
..
cluster Add CLUSTER SLOT-STATS command (#14039) 2025-07-01 20:26:51 +03:00
moduleapi Module set/get config API (#14051) 2025-07-03 13:46:33 +03:00
type Add XDELEX and XACKDEL commands for stream (#14130) 2025-07-01 21:00:42 +08:00
acl-v2.tcl Fix Read/Write key pattern selector (CVE-2024-51741) 2025-01-13 21:20:19 +02:00
acl.tcl Free current client asynchronously after user permissions changes (#13274) 2024-05-30 22:09:30 +08:00
aofrw.tcl Attempt to solve MacOS CI issues in GH Actions (#12013) 2023-04-12 09:19:21 +03:00
auth.tcl Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
bitfield.tcl Add BITFIELD_RO basic tests for non-repl use cases (#12187) 2023-05-18 12:16:46 +03:00
bitops.tcl Implement DIFF, DIFF1, ANDOR and ONE for BITOP (#13898) 2025-05-20 10:45:50 +03:00
client-eviction.tcl Add thread sanitizer run to daily CI (#13964) 2025-06-02 10:13:23 +03:00
dump.tcl Fix RESTORE with TTL (#14071) 2025-05-28 08:02:10 +03:00
expire.tcl New config: lazyexpire-nested-arbitrary-keys (#14149) 2025-07-01 15:28:13 +08:00
functions.tcl Trigger Lua GC after script loading (#13407) 2024-07-16 09:28:47 +08:00
geo.tcl adding geo command edge cases tests (#12274) 2023-06-20 12:50:03 +03:00
hyperloglog.tcl Fix bug in PFMERGE command (#13672) 2024-12-18 14:41:04 +08:00
info-command.tcl Make INFO command variadic (#6891) 2022-02-08 13:14:42 +02:00
info-keysizes.tcl Fix keysizes - SPOP with count (case 3) and SETRANGE (#14028) 2025-05-19 16:59:21 +03:00
info.tcl Reduce the main thread blocking in clients cron (#13900) 2025-06-30 09:37:17 +08:00
introspection-2.tcl RED-129256, Fix TOUCH command from script in no-touch mode (#13512) 2024-09-12 11:33:26 +03:00
introspection.tcl Add config base to vector-sets and hnsw thread config (#14082) 2025-06-16 10:06:43 +08:00
keyspace.tcl Prevent pattern matching abuse (CVE-2024-31228) 2024-10-08 20:55:44 +03:00
latency-monitor.tcl Add printing for LATENCY related tests (#12514) 2023-08-27 11:42:55 +03:00
lazyfree.tcl Fix timing issue in lazyfree test (#13926) 2025-04-13 20:32:16 +08:00
limits.tcl Improve test suite to handle external servers better. (#9033) 2021-06-09 15:13:24 +03:00
maxmemory.tcl Stabilize tests for IO threading (#14138) 2025-06-25 15:36:40 +08:00
memefficiency.tcl Make Active defrag big list test much faster (#14157) 2025-06-30 16:56:17 +03:00
multi.tcl Fix propagation of entries_read by calling streamPropagateGroupID unconditionally (#12898) 2024-02-29 09:48:20 +02:00
networking.tcl Reduce the main thread blocking in clients cron (#13900) 2025-06-30 09:37:17 +08:00
obuf-limits.tcl Reduce the main thread blocking in clients cron (#13900) 2025-06-30 09:37:17 +08:00
oom-score-adj.tcl Check user's oom_score_adj write permission for oom-score-adj test (#13111) 2024-03-05 14:42:28 +02:00
other.tcl Cluster compatibility check (#13846) 2025-03-20 10:35:53 +08:00
pause.tcl Fix potential infinite loop of RANDOMKEY during client pause (#13863) 2025-03-20 21:32:12 +08:00
printver.tcl Print version info before running the test 2011-05-20 11:44:54 +02:00
protocol.tcl Fix crash due to cron argv release (#13725) 2025-01-08 09:57:23 +08:00
pubsub.tcl Fix order of KSN for hgetex command (#13931) 2025-04-14 13:31:31 +03:00
pubsubshard.tcl Async IO Threads (#13695) 2024-12-23 14:16:40 +08:00
querybuf.tcl Adding AGPLv3 as a license option to Redis! (#13997) 2025-05-01 14:04:22 +01:00
quit.tcl flushSlavesOutputBuffers should not write to replicas scheduled to drop (#12242) 2023-06-12 14:05:34 +03:00
replybufsize.tcl Introduce debug command to disable reply buffer resizing (#10360) 2022-03-01 14:40:29 +02:00
scan.tcl Revert "improve performance for scan command when matching data type (#12395)" 2025-02-05 20:49:42 +02:00
scripting.tcl Fix memory leak of jemalloc tcache on function flush command (#13661) 2024-11-21 14:12:58 +03:00
shutdown.tcl Tests: Do not save an RDB by default and add a SIGTERM default AOFRW test (#12064) 2023-04-18 16:14:26 +03:00
slowlog.tcl Exit early if slowlog/acllog max len set to zero (#12965) 2024-01-22 16:01:04 -08:00
sort.tcl Fix get # option in sort command (#13608) 2024-10-22 09:55:00 +08:00
tls.tcl Add support for reading encrypted keyfiles. (#8644) 2021-03-22 13:27:46 +02:00
tracking.tcl Bump codespell from 2.2.4 to 2.2.5 (#12557) 2023-09-08 16:10:17 +03:00
violations.tcl Run large-memory tests as solo. (#10626) 2022-04-24 17:29:35 +03:00
wait.tcl WAITAOF: Update fsynced_reploff_pending even if there's nothing to fsync (#12622) 2023-09-28 17:19:20 +03:00