Unverified Commit 6af02100 authored by Viktor Söderqvist's avatar Viktor Söderqvist Committed by GitHub
Browse files

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)
parent 28546373
...@@ -3349,8 +3349,8 @@ int modulePopulateReplicationInfoStructure(void *ri, int structver) { ...@@ -3349,8 +3349,8 @@ int modulePopulateReplicationInfoStructure(void *ri, int structver) {
* is returned. * is returned.
* *
* When the client exist and the `ci` pointer is not NULL, but points to * When the client exist and the `ci` pointer is not NULL, but points to
* a structure of type RedisModuleClientInfo, previously initialized with * a structure of type RedisModuleClientInfoV1, previously initialized with
* the correct REDISMODULE_CLIENTINFO_INITIALIZER, the structure is populated * the correct REDISMODULE_CLIENTINFO_INITIALIZER_V1, the structure is populated
* with the following fields: * with the following fields:
* *
* uint64_t flags; // REDISMODULE_CLIENTINFO_FLAG_* * uint64_t flags; // REDISMODULE_CLIENTINFO_FLAG_*
......
...@@ -656,6 +656,8 @@ typedef struct RedisModuleClientInfo { ...@@ -656,6 +656,8 @@ typedef struct RedisModuleClientInfo {
#define RedisModuleClientInfo RedisModuleClientInfoV1 #define RedisModuleClientInfo RedisModuleClientInfoV1
#define REDISMODULE_CLIENTINFO_INITIALIZER_V1 { .version = 1 }
#define REDISMODULE_REPLICATIONINFO_VERSION 1 #define REDISMODULE_REPLICATIONINFO_VERSION 1
typedef struct RedisModuleReplicationInfo { typedef struct RedisModuleReplicationInfo {
uint64_t version; /* Not used since this structure is never passed uint64_t version; /* Not used since this structure is never passed
......
...@@ -240,9 +240,17 @@ int test_clientinfo(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) ...@@ -240,9 +240,17 @@ int test_clientinfo(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
(void) argv; (void) argv;
(void) argc; (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"); RedisModule_ReplyWithError(ctx, "failed to get client info");
return REDISMODULE_OK; return REDISMODULE_OK;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment