Skip to content

Commit 4df4443

Browse files
committed
Merge branch 'feat-ros-8.2' of github.com:redis/docs into feat-ros-8.2
2 parents 6e3e89d + 58d847e commit 4df4443

File tree

1 file changed

+290
-11
lines changed

1 file changed

+290
-11
lines changed

content/develop/reference/modules/modules-api-ref.md

Lines changed: 290 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ weight: 1
5858
* [Server hooks implementation](#section-server-hooks-implementation)
5959
* [Module Configurations API](#section-module-configurations-api)
6060
* [RDB load/save API](#section-rdb-load-save-api)
61+
* [Config access API](#section-config-access-api)
6162
* [Key eviction API](#section-key-eviction-api)
6263
* [Miscellaneous APIs](#section-miscellaneous-apis)
6364
* [Defrag API](#section-defrag-api)
@@ -3166,7 +3167,7 @@ The returned `RedisModuleString` objects should be released with
31663167

31673168
mstime_t RedisModule_HashFieldMinExpire(RedisModuleKey *key);
31683169

3169-
**Available since:** unreleased
3170+
**Available since:** 8.0.0
31703171

31713172

31723173
Retrieves the minimum expiration time of fields in a hash.
@@ -5042,7 +5043,13 @@ is interested in. This can be an ORed mask of any of the following flags:
50425043
this notification is wrong and discourage. It will
50435044
cause the read command that trigger the event to be
50445045
replicated to the AOF/Replica.
5045-
- `REDISMODULE_NOTIFY_ALL`: All events (Excluding `REDISMODULE_NOTIFY_KEYMISS`)
5046+
5047+
- `REDISMODULE_NOTIFY_NEW`: New key notification
5048+
- `REDISMODULE_NOTIFY_OVERWRITTEN`: Overwritten events
5049+
- `REDISMODULE_NOTIFY_TYPE_CHANGED`: Type-changed events
5050+
- `REDISMODULE_NOTIFY_ALL`: All events (Excluding `REDISMODULE_NOTIFY_KEYMISS`,
5051+
REDISMODULE_NOTIFY_NEW, REDISMODULE_NOTIFY_OVERWRITTEN
5052+
and REDISMODULE_NOTIFY_TYPE_CHANGED)
50465053
- `REDISMODULE_NOTIFY_LOADED`: A special notification available only for modules,
50475054
indicates that the key was loaded from persistence.
50485055
Notice, when this event fires, the given key
@@ -5650,7 +5657,7 @@ If the user is able to access the key then `REDISMODULE_OK` is returned, otherwi
56505657
RedisModuleString *prefix,
56515658
int flags);
56525659

5653-
**Available since:** unreleased
5660+
**Available since:** 8.0.0
56545661

56555662
Check if the user can access keys matching the given key prefix according to the ACLs
56565663
attached to the user and the flags representing key access. The flags are the same that
@@ -7435,7 +7442,7 @@ Create an integer config that server clients can interact with via the
74357442

74367443
int RedisModule_LoadDefaultConfigs(RedisModuleCtx *ctx);
74377444

7438-
**Available since:** unreleased
7445+
**Available since:** 8.0.0
74397446

74407447
Applies all default configurations for the parameters the module registered.
74417448
Only call this function if the module would like to make changes to the
@@ -7542,12 +7549,273 @@ Example:
75427549

75437550
const char* RedisModule_GetInternalSecret(RedisModuleCtx *ctx, size_t *len);
75447551

7545-
**Available since:** unreleased
7552+
**Available since:** 8.0.0
75467553

75477554
Returns the internal secret of the cluster.
75487555
Should be used to authenticate as an internal connection to a node in the
75497556
cluster, and by that gain the permissions to execute internal commands.
75507557

7558+
<span id="section-config-access-api"></span>
7559+
7560+
## Config access API
7561+
7562+
<span id="RedisModule_ConfigIteratorCreate"></span>
7563+
7564+
### `RedisModule_ConfigIteratorCreate`
7565+
7566+
RedisModuleConfigIterator *RedisModule_ConfigIteratorCreate(RedisModuleCtx *ctx,
7567+
const char *pattern);
7568+
7569+
**Available since:** unreleased
7570+
7571+
Get an iterator to all configs.
7572+
Optional `ctx` can be provided if use of auto-memory is desired.
7573+
Optional `pattern` can be provided to filter configs by name. If `pattern` is
7574+
NULL all configs will be returned.
7575+
7576+
The returned iterator can be used to iterate over all configs using
7577+
[`RedisModule_ConfigIteratorNext()`](#RedisModule_ConfigIteratorNext).
7578+
7579+
Example usage:
7580+
```
7581+
// Below is same as [`RedisModule_ConfigIteratorCreate`](#RedisModule_ConfigIteratorCreate)(ctx, NULL)
7582+
`RedisModuleConfigIterator` *iter = [`RedisModule_ConfigIteratorCreate`](#RedisModule_ConfigIteratorCreate)(ctx, "*");
7583+
const char *config_name = NULL;
7584+
while ((`config_name` = [`RedisModule_ConfigIteratorNext`](#RedisModule_ConfigIteratorNext)(iter)) != NULL) {
7585+
RedisModuleString *value = NULL;
7586+
if (RedisModule_ConfigGet(ctx, config_name, &value) == REDISMODULE_OK) {
7587+
// Do something with `value`...
7588+
RedisModule_FreeString(ctx, value);
7589+
}
7590+
}
7591+
[`RedisModule_ConfigIteratorRelease`](#RedisModule_ConfigIteratorRelease)(ctx, iter);
7592+
7593+
// Or optionally one can check the type to get the config value directly
7594+
// via the appropriate API in case performance is of consideration
7595+
iter = [`RedisModule_ConfigIteratorCreate`](#RedisModule_ConfigIteratorCreate)(ctx, "*");
7596+
while ((`config_name` = [`RedisModule_ConfigIteratorNext`](#RedisModule_ConfigIteratorNext)(iter)) != NULL) {
7597+
RedisModuleConfigType type = RedisModule_ConfigGetType(config_name);
7598+
if (type == REDISMODULE_CONFIG_TYPE_STRING) {
7599+
RedisModuleString *value;
7600+
RedisModule_ConfigGet(ctx, config_name, &value);
7601+
// Do something with `value`...
7602+
RedisModule_FreeString(ctx, value);
7603+
} if (type == REDISMODULE_CONFIG_TYPE_NUMERIC) {
7604+
long long value;
7605+
RedisModule_ConfigGetNumeric(ctx, config_name, &value);
7606+
// Do something with `value`...
7607+
} else if (type == REDISMODULE_CONFIG_TYPE_BOOL) {
7608+
int value;
7609+
RedisModule_ConfigGetBool(ctx, config_name, &value);
7610+
// Do something with `value`...
7611+
} else if (type == REDISMODULE_CONFIG_TYPE_ENUM) {
7612+
RedisModuleString *value;
7613+
RedisModule_ConfigGetEnum(ctx, config_name, &value);
7614+
// Do something with `value`...
7615+
RedisModule_Free(value);
7616+
}
7617+
}
7618+
[`RedisModule_ConfigIteratorRelease`](#RedisModule_ConfigIteratorRelease)(ctx, iter);
7619+
```
7620+
7621+
Returns a pointer to `RedisModuleConfigIterator`. Unless auto-memory is enabled
7622+
the caller is responsible for freeing the iterator using
7623+
[`RedisModule_ConfigIteratorRelease()`](#RedisModule_ConfigIteratorRelease).
7624+
7625+
<span id="RedisModule_ConfigIteratorRelease"></span>
7626+
7627+
### `RedisModule_ConfigIteratorRelease`
7628+
7629+
void RedisModule_ConfigIteratorRelease(RedisModuleCtx *ctx,
7630+
RedisModuleConfigIterator *iter);
7631+
7632+
**Available since:** unreleased
7633+
7634+
Release the iterator returned by [`RedisModule_ConfigIteratorCreate()`](#RedisModule_ConfigIteratorCreate). If auto-memory
7635+
is enabled and manual release is needed one must pass the same `RedisModuleCtx`
7636+
that was used to create the iterator.
7637+
7638+
<span id="RedisModule_ConfigGetType"></span>
7639+
7640+
### `RedisModule_ConfigGetType`
7641+
7642+
int RedisModule_ConfigGetType(const char *name, RedisModuleConfigType *res);
7643+
7644+
**Available since:** unreleased
7645+
7646+
Get the type of a config as `RedisModuleConfigType`. One may use this in order
7647+
to get or set the values of the config with the appropriate function if the
7648+
generic [`RedisModule_ConfigGet`](#RedisModule_ConfigGet) and [`RedisModule_ConfigSet`](#RedisModule_ConfigSet) APIs are performing
7649+
poorly.
7650+
7651+
Intended usage of this function is when iteration over the configs is
7652+
performed. See [`RedisModule_ConfigIteratorNext()`](#RedisModule_ConfigIteratorNext) for example usage. If setting
7653+
or getting individual configs one can check the config type by hand in
7654+
redis.conf (or via other sources if config is added by a module) and use the
7655+
appropriate function without the need to call this function.
7656+
7657+
Explanation of config types:
7658+
- `REDISMODULE_CONFIG_TYPE_BOOL`: Config is a boolean. One can use `RedisModule_Config`(Get/Set)Bool
7659+
- `REDISMODULE_CONFIG_TYPE_NUMERIC`: Config is a numeric value. One can use `RedisModule_Config`(Get/Set)Numeric
7660+
- `REDISMODULE_CONFIG_TYPE_STRING`: Config is a string. One can use the generic `RedisModule_Config`(Get/Set)
7661+
- `REDISMODULE_CONFIG_TYPE_ENUM`: Config is an enum. One can use `RedisModule_Config`(Get/Set)Enum
7662+
7663+
If a config with the given name exists `res` is populated with its type, else
7664+
`REDISMODULE_ERR` is returned.
7665+
7666+
<span id="RedisModule_ConfigIteratorNext"></span>
7667+
7668+
### `RedisModule_ConfigIteratorNext`
7669+
7670+
const char *RedisModule_ConfigIteratorNext(RedisModuleConfigIterator *iter);
7671+
7672+
**Available since:** unreleased
7673+
7674+
Go to the next element of the config iterator.
7675+
7676+
Returns the name of the next config, or NULL if there are no more configs.
7677+
Returned string is non-owning and thus should not be freed.
7678+
If a pattern was provided when creating the iterator, only configs matching
7679+
the pattern will be returned.
7680+
7681+
See [`RedisModule_ConfigIteratorCreate()`](#RedisModule_ConfigIteratorCreate) for example usage.
7682+
7683+
<span id="RedisModule_ConfigGet"></span>
7684+
7685+
### `RedisModule_ConfigGet`
7686+
7687+
int RedisModule_ConfigGet(RedisModuleCtx *ctx,
7688+
const char *name,
7689+
RedisModuleString **res);
7690+
7691+
**Available since:** unreleased
7692+
7693+
Get the value of a config as a string. This function can be used to get the
7694+
value of any config, regardless of its type.
7695+
7696+
The string is allocated by the module and must be freed by the caller unless
7697+
auto memory is enabled.
7698+
7699+
If the config does not exist, `REDISMODULE_ERR` is returned, else `REDISMODULE_OK`
7700+
is returned and `res` is populated with the value.
7701+
7702+
<span id="RedisModule_ConfigGetBool"></span>
7703+
7704+
### `RedisModule_ConfigGetBool`
7705+
7706+
int RedisModule_ConfigGetBool(RedisModuleCtx *ctx, const char *name, int *res);
7707+
7708+
**Available since:** unreleased
7709+
7710+
Get the value of a bool config.
7711+
7712+
If the config does not exist or is not a bool config, `REDISMODULE_ERR` is
7713+
returned, else `REDISMODULE_OK` is returned and `res` is populated with the
7714+
value.
7715+
7716+
<span id="RedisModule_ConfigGetEnum"></span>
7717+
7718+
### `RedisModule_ConfigGetEnum`
7719+
7720+
int RedisModule_ConfigGetEnum(RedisModuleCtx *ctx,
7721+
const char *name,
7722+
RedisModuleString **res);
7723+
7724+
**Available since:** unreleased
7725+
7726+
Get the value of an enum config.
7727+
7728+
If the config does not exist or is not an enum config, `REDISMODULE_ERR` is
7729+
returned, else `REDISMODULE_OK` is returned and `res` is populated with the value.
7730+
If the config has multiple arguments they are returned as a space-separated
7731+
string.
7732+
7733+
<span id="RedisModule_ConfigGetNumeric"></span>
7734+
7735+
### `RedisModule_ConfigGetNumeric`
7736+
7737+
int RedisModule_ConfigGetNumeric(RedisModuleCtx *ctx,
7738+
const char *name,
7739+
long long *res);
7740+
7741+
**Available since:** unreleased
7742+
7743+
Get the value of a numeric config.
7744+
7745+
If the config does not exist or is not a numeric config, `REDISMODULE_ERR` is
7746+
returned, else `REDISMODULE_OK` is returned and `res` is populated with the
7747+
value.
7748+
7749+
<span id="RedisModule_ConfigSet"></span>
7750+
7751+
### `RedisModule_ConfigSet`
7752+
7753+
int RedisModule_ConfigSet(RedisModuleCtx *ctx,
7754+
const char *name,
7755+
RedisModuleString *value,
7756+
RedisModuleString **err);
7757+
7758+
**Available since:** unreleased
7759+
7760+
Set the value of a config.
7761+
7762+
This function can be used to set the value of any config, regardless of its
7763+
type. If the config is multi-argument, the value must be a space-separated
7764+
string.
7765+
7766+
If the value failed to be set `REDISMODULE_ERR` will be returned and if `err`
7767+
is not NULL, it will be populated with an error message.
7768+
7769+
<span id="RedisModule_ConfigSetBool"></span>
7770+
7771+
### `RedisModule_ConfigSetBool`
7772+
7773+
int RedisModule_ConfigSetBool(RedisModuleCtx *ctx,
7774+
const char *name,
7775+
int value,
7776+
RedisModuleString **err);
7777+
7778+
**Available since:** unreleased
7779+
7780+
Set the value of a bool config.
7781+
7782+
See [`RedisModule_ConfigSet`](#RedisModule_ConfigSet) for return value.
7783+
7784+
<span id="RedisModule_ConfigSetEnum"></span>
7785+
7786+
### `RedisModule_ConfigSetEnum`
7787+
7788+
int RedisModule_ConfigSetEnum(RedisModuleCtx *ctx,
7789+
const char *name,
7790+
RedisModuleString *value,
7791+
RedisModuleString **err);
7792+
7793+
**Available since:** unreleased
7794+
7795+
Set the value of an enum config.
7796+
7797+
If the config is multi-argument the value parameter must be a space-separated
7798+
string.
7799+
7800+
See [`RedisModule_ConfigSet`](#RedisModule_ConfigSet) for return value.
7801+
7802+
<span id="RedisModule_ConfigSetNumeric"></span>
7803+
7804+
### `RedisModule_ConfigSetNumeric`
7805+
7806+
int RedisModule_ConfigSetNumeric(RedisModuleCtx *ctx,
7807+
const char *name,
7808+
long long value,
7809+
RedisModuleString **err);
7810+
7811+
**Available since:** unreleased
7812+
7813+
Set the value of a numeric config.
7814+
If the value passed is meant to be a percentage, it should be passed as a
7815+
negative value.
7816+
7817+
See [`RedisModule_ConfigSet`](#RedisModule_ConfigSet) for return value.
7818+
75517819
<span id="section-key-eviction-api"></span>
75527820

75537821
## Key eviction API
@@ -7801,7 +8069,7 @@ may allocate that is not tied to a specific data type.
78018069
int RedisModule_RegisterDefragFunc2(RedisModuleCtx *ctx,
78028070
RedisModuleDefragFunc2 cb);
78038071

7804-
**Available since:** unreleased
8072+
**Available since:** 8.0.0
78058073

78068074
Register a defrag callback for global data, i.e. anything that the module
78078075
may allocate that is not tied to a specific data type.
@@ -7817,7 +8085,7 @@ in and indicate that it should be called again later, or is it done (returned 0)
78178085
RedisModuleDefragFunc start,
78188086
RedisModuleDefragFunc end);
78198087

7820-
**Available since:** unreleased
8088+
**Available since:** 8.0.0
78218089

78228090
Register a defrag callbacks that will be called when defrag operation starts and ends.
78238091

@@ -7914,7 +8182,7 @@ be used again.
79148182

79158183
void *RedisModule_DefragAllocRaw(RedisModuleDefragCtx *ctx, size_t size);
79168184

7917-
**Available since:** unreleased
8185+
**Available since:** 8.0.0
79188186

79198187
Allocate memory for defrag purposes
79208188

@@ -7934,7 +8202,7 @@ allow to support more complex defrag usecases.
79348202

79358203
void RedisModule_DefragFreeRaw(RedisModuleDefragCtx *ctx, void *ptr);
79368204

7937-
**Available since:** unreleased
8205+
**Available since:** 8.0.0
79388206

79398207
Free memory for defrag purposes
79408208

@@ -7968,7 +8236,7 @@ on the Redis side is dropped as soon as the command callback returns).
79688236
RedisModuleDefragDictValueCallback valueCB,
79698237
RedisModuleString **seekTo);
79708238

7971-
**Available since:** unreleased
8239+
**Available since:** 8.0.0
79728240

79738241
Defragment a Redis Module Dictionary by scanning its contents and calling a value
79748242
callback for each value.
@@ -8061,6 +8329,18 @@ There is no guarantee that this info is always available, so this may return -1.
80618329
* [`RedisModule_CommandFilterArgReplace`](#RedisModule_CommandFilterArgReplace)
80628330
* [`RedisModule_CommandFilterArgsCount`](#RedisModule_CommandFilterArgsCount)
80638331
* [`RedisModule_CommandFilterGetClientId`](#RedisModule_CommandFilterGetClientId)
8332+
* [`RedisModule_ConfigGet`](#RedisModule_ConfigGet)
8333+
* [`RedisModule_ConfigGetBool`](#RedisModule_ConfigGetBool)
8334+
* [`RedisModule_ConfigGetEnum`](#RedisModule_ConfigGetEnum)
8335+
* [`RedisModule_ConfigGetNumeric`](#RedisModule_ConfigGetNumeric)
8336+
* [`RedisModule_ConfigGetType`](#RedisModule_ConfigGetType)
8337+
* [`RedisModule_ConfigIteratorCreate`](#RedisModule_ConfigIteratorCreate)
8338+
* [`RedisModule_ConfigIteratorNext`](#RedisModule_ConfigIteratorNext)
8339+
* [`RedisModule_ConfigIteratorRelease`](#RedisModule_ConfigIteratorRelease)
8340+
* [`RedisModule_ConfigSet`](#RedisModule_ConfigSet)
8341+
* [`RedisModule_ConfigSetBool`](#RedisModule_ConfigSetBool)
8342+
* [`RedisModule_ConfigSetEnum`](#RedisModule_ConfigSetEnum)
8343+
* [`RedisModule_ConfigSetNumeric`](#RedisModule_ConfigSetNumeric)
80648344
* [`RedisModule_CreateCommand`](#RedisModule_CreateCommand)
80658345
* [`RedisModule_CreateDataType`](#RedisModule_CreateDataType)
80668346
* [`RedisModule_CreateDict`](#RedisModule_CreateDict)
@@ -8373,4 +8653,3 @@ There is no guarantee that this info is always available, so this may return -1.
83738653
* [`RedisModule_ZsetRem`](#RedisModule_ZsetRem)
83748654
* [`RedisModule_ZsetScore`](#RedisModule_ZsetScore)
83758655
* [`RedisModule__Assert`](#RedisModule__Assert)
8376-

0 commit comments

Comments
 (0)