diff options
author | antirez <antirez@gmail.com> | 2019-10-23 10:14:23 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2019-10-23 18:39:53 +0200 |
commit | 8ec2fc3969b5f66fbcab82b7470ac36ec92f2ee9 (patch) | |
tree | 73e3c4a1692f7d4441c8218bda2e0c7b052ecc2d | |
parent | db8c9a8520ae4c3cbc8d32173385a0a82a1468aa (diff) | |
download | redis-8ec2fc3969b5f66fbcab82b7470ac36ec92f2ee9.tar.gz |
Modules hooks: unify structures definitions.
-rw-r--r-- | src/module.c | 19 | ||||
-rw-r--r-- | src/redismodule.h | 48 |
2 files changed, 42 insertions, 25 deletions
diff --git a/src/module.c b/src/module.c index 37d89fdfe..8957849fd 100644 --- a/src/module.c +++ b/src/module.c @@ -1534,21 +1534,10 @@ unsigned long long RM_GetClientId(RedisModuleCtx *ctx) { * then REDISMODULE_ERR is returned. Otherwise the function returns * REDISMODULE_OK and the structure pointed by 'ci' gets populated. */ -/* Note that we may have multiple versions of the client info structure, - * as the API evolves. */ -struct moduleClientInfoV1 { - uint64_t version; /* Version of this structure for ABI compat. */ - uint64_t flags; /* REDISMODULE_CLIENTINFO_FLAG_* */ - uint64_t id; /* Client ID. */ - char addr[46]; /* IPv4 or IPv6 address. */ - uint16_t port; /* TCP port. */ - uint16_t db; /* Selected DB. */ -}; - int modulePopulateClientInfoStructure(void *ci, client *client, int structver) { if (structver != 1) return REDISMODULE_ERR; - struct moduleClientInfoV1 *ci1 = ci; + RedisModuleClientInfoV1 *ci1 = ci; memset(ci1,0,sizeof(*ci1)); ci1->version = structver; if (client->flags & CLIENT_MULTI) @@ -5738,12 +5727,12 @@ void ModuleForkDoneHandler(int exitcode, int bysignal) { * The data pointer can be casted to a RedisModuleFlushInfo * structure with the following fields: * - * int async; // True if the flush is done in a thread. + * int32_t async; // True if the flush is done in a thread. * See for instance FLUSHALL ASYNC. * In this case the END callback is invoked * immediately after the database is put * in the free list of the thread. - * int dbnum; // Flushed database number, -1 for all the DBs + * int32_t dbnum; // Flushed database number, -1 for all the DBs * in the case of the FLUSHALL operation. * * The start event is called *before* the operation is initated, thus @@ -5876,7 +5865,7 @@ void moduleFireServerEvent(uint64_t eid, int subid, void *data) { ctx.client = moduleFreeContextReusedClient; void *moduledata = NULL; - struct moduleClientInfoV1 civ1; + RedisModuleClientInfoV1 civ1; if (eid == REDISMODULE_EVENT_CLIENT_CHANGE) { modulePopulateClientInfoStructure(&civ1,data, el->event.dataver); diff --git a/src/redismodule.h b/src/redismodule.h index 2a413a3c8..d8f4fb901 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -247,6 +247,44 @@ static RedisModuleEvent #define REDISMODULE_CLIENTINFO_FLAG_UNIXSOCKET (1<<4) #define REDISMODULE_CLIENTINFO_FLAG_MULTI (1<<5) +/* Here we take all the structures that the module pass to the core + * and the other way around. Notably the list here contains the structures + * used by the hooks API RedisModule_RegisterToServerEvent(). + * + * The structures always start with a 'version' field. This is useful + * when we want to pass a reference to the structure to the core APIs, + * for the APIs to fill the structure. In that case, the structure 'version' + * field is initialized before passing it to the core, so that the core is + * able to cast the pointer to the appropriate structure version. In this + * way we obtain ABI compatibility. + * + * Here we'll list all the structure versions in case they evolve over time, + * however using a define, we'll make sure to use the last version as the + * public name for the module to use. */ + +#define REDISMODULE_CLIENTINFO_VERSION 1 +typedef struct RedisModuleClientInfo { + uint64_t version; /* Version of this structure for ABI compat. */ + uint64_t flags; /* REDISMODULE_CLIENTINFO_FLAG_* */ + uint64_t id; /* Client ID. */ + char addr[46]; /* IPv4 or IPv6 address. */ + uint16_t port; /* TCP port. */ + uint16_t db; /* Selected DB. */ +} RedisModuleClientInfoV1; + +#define RedisModuleClientInfo RedisModuleClientInfoV1 + +#define REDISMODULE_FLUSHINFO_VERSION 1 +typedef struct RedisModuleFlushInfo { + uint64_t version; /* Not used since this structure is never passed + from the module to the core right now. Here + for future compatibility. */ + int32_t sync; /* Synchronous or threaded flush?. */ + int32_t dbnum; /* Flushed database number, -1 for ALL. */ +} RedisModuleFlushInfoV1; + +#define RedisModuleFlushInfo RedisModuleFlushInfoV1 + /* ------------------------- End of common defines ------------------------ */ #ifndef REDISMODULE_CORE @@ -300,16 +338,6 @@ typedef struct RedisModuleTypeMethods { int aux_save_triggers; } RedisModuleTypeMethods; -#define REDISMODULE_CLIENTINFO_VERSION 1 -typedef struct RedisModuleClientInfo { - uint64_t version; /* Version of this structure for ABI compat. */ - uint64_t flags; /* REDISMODULE_CLIENTINFO_FLAG_* */ - uint64_t id; /* Client ID. */ - char addr[46]; /* IPv4 or IPv6 address. */ - uint16_t port; /* TCP port. */ - uint16_t db; /* Selected DB. */ -} RedisModuleClientInfo; - #define REDISMODULE_GET_API(name) \ RedisModule_GetApi("RedisModule_" #name, ((void **)&RedisModule_ ## name)) |