summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2022-06-27 07:29:05 +0200
committerGitHub <noreply@github.com>2022-06-27 08:29:05 +0300
commit6af021007a70f42e41f2a8abda3719d68b15ada4 (patch)
treeba43ef9d78b19768e20d00af3916a3f291df34fd
parent2854637385f6f44661ebd8833d852c068039e641 (diff)
downloadredis-6af021007a70f42e41f2a8abda3719d68b15ada4.tar.gz
Add missing REDISMODULE_CLIENTINFO_INITIALIZER (#10885)
The module API docs mentions this macro, but it was not defined (so no one could have used it). Instead of adding it as is, we decided to add a _V1 macro, so that if / when we some day extend this struct, modules that use this API and don't need the extra fields, will still use the old version and still be compatible with older redis version (despite being compiled with newer redismodule.h)
-rw-r--r--src/module.c4
-rw-r--r--src/redismodule.h2
-rw-r--r--tests/modules/misc.c12
3 files changed, 14 insertions, 4 deletions
diff --git a/src/module.c b/src/module.c
index fd2de983d..3ea8433f8 100644
--- a/src/module.c
+++ b/src/module.c
@@ -3349,8 +3349,8 @@ int modulePopulateReplicationInfoStructure(void *ri, int structver) {
* is returned.
*
* When the client exist and the `ci` pointer is not NULL, but points to
- * a structure of type RedisModuleClientInfo, previously initialized with
- * the correct REDISMODULE_CLIENTINFO_INITIALIZER, the structure is populated
+ * a structure of type RedisModuleClientInfoV1, previously initialized with
+ * the correct REDISMODULE_CLIENTINFO_INITIALIZER_V1, the structure is populated
* with the following fields:
*
* uint64_t flags; // REDISMODULE_CLIENTINFO_FLAG_*
diff --git a/src/redismodule.h b/src/redismodule.h
index a55c2e712..f1019fc2c 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -656,6 +656,8 @@ typedef struct RedisModuleClientInfo {
#define RedisModuleClientInfo RedisModuleClientInfoV1
+#define REDISMODULE_CLIENTINFO_INITIALIZER_V1 { .version = 1 }
+
#define REDISMODULE_REPLICATIONINFO_VERSION 1
typedef struct RedisModuleReplicationInfo {
uint64_t version; /* Not used since this structure is never passed
diff --git a/tests/modules/misc.c b/tests/modules/misc.c
index c9ebcc5f9..64b456904 100644
--- a/tests/modules/misc.c
+++ b/tests/modules/misc.c
@@ -240,9 +240,17 @@ int test_clientinfo(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
(void) argv;
(void) argc;
- RedisModuleClientInfo ci = { .version = REDISMODULE_CLIENTINFO_VERSION };
+ RedisModuleClientInfoV1 ci = REDISMODULE_CLIENTINFO_INITIALIZER_V1;
+ uint64_t client_id = RedisModule_GetClientId(ctx);
- if (RedisModule_GetClientInfoById(&ci, RedisModule_GetClientId(ctx)) == REDISMODULE_ERR) {
+ /* Check expected result from the V1 initializer. */
+ assert(ci.version == 1);
+ /* Trying to populate a future version of the struct should fail. */
+ ci.version = REDISMODULE_CLIENTINFO_VERSION + 1;
+ assert(RedisModule_GetClientInfoById(&ci, client_id) == REDISMODULE_ERR);
+
+ ci.version = 1;
+ if (RedisModule_GetClientInfoById(&ci, client_id) == REDISMODULE_ERR) {
RedisModule_ReplyWithError(ctx, "failed to get client info");
return REDISMODULE_OK;
}