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; }