Modules hooks: unify structures definitions.
This commit is contained in:
parent
db8c9a8520
commit
8ec2fc3969
19
src/module.c
19
src/module.c
@ -1534,21 +1534,10 @@ unsigned long long RM_GetClientId(RedisModuleCtx *ctx) {
|
|||||||
* then REDISMODULE_ERR is returned. Otherwise the function returns
|
* then REDISMODULE_ERR is returned. Otherwise the function returns
|
||||||
* REDISMODULE_OK and the structure pointed by 'ci' gets populated. */
|
* 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) {
|
int modulePopulateClientInfoStructure(void *ci, client *client, int structver) {
|
||||||
if (structver != 1) return REDISMODULE_ERR;
|
if (structver != 1) return REDISMODULE_ERR;
|
||||||
|
|
||||||
struct moduleClientInfoV1 *ci1 = ci;
|
RedisModuleClientInfoV1 *ci1 = ci;
|
||||||
memset(ci1,0,sizeof(*ci1));
|
memset(ci1,0,sizeof(*ci1));
|
||||||
ci1->version = structver;
|
ci1->version = structver;
|
||||||
if (client->flags & CLIENT_MULTI)
|
if (client->flags & CLIENT_MULTI)
|
||||||
@ -5738,12 +5727,12 @@ void ModuleForkDoneHandler(int exitcode, int bysignal) {
|
|||||||
* The data pointer can be casted to a RedisModuleFlushInfo
|
* The data pointer can be casted to a RedisModuleFlushInfo
|
||||||
* structure with the following fields:
|
* 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.
|
* See for instance FLUSHALL ASYNC.
|
||||||
* In this case the END callback is invoked
|
* In this case the END callback is invoked
|
||||||
* immediately after the database is put
|
* immediately after the database is put
|
||||||
* in the free list of the thread.
|
* 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.
|
* in the case of the FLUSHALL operation.
|
||||||
*
|
*
|
||||||
* The start event is called *before* the operation is initated, thus
|
* 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;
|
ctx.client = moduleFreeContextReusedClient;
|
||||||
|
|
||||||
void *moduledata = NULL;
|
void *moduledata = NULL;
|
||||||
struct moduleClientInfoV1 civ1;
|
RedisModuleClientInfoV1 civ1;
|
||||||
if (eid == REDISMODULE_EVENT_CLIENT_CHANGE) {
|
if (eid == REDISMODULE_EVENT_CLIENT_CHANGE) {
|
||||||
modulePopulateClientInfoStructure(&civ1,data,
|
modulePopulateClientInfoStructure(&civ1,data,
|
||||||
el->event.dataver);
|
el->event.dataver);
|
||||||
|
@ -247,6 +247,44 @@ static RedisModuleEvent
|
|||||||
#define REDISMODULE_CLIENTINFO_FLAG_UNIXSOCKET (1<<4)
|
#define REDISMODULE_CLIENTINFO_FLAG_UNIXSOCKET (1<<4)
|
||||||
#define REDISMODULE_CLIENTINFO_FLAG_MULTI (1<<5)
|
#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 ------------------------ */
|
/* ------------------------- End of common defines ------------------------ */
|
||||||
|
|
||||||
#ifndef REDISMODULE_CORE
|
#ifndef REDISMODULE_CORE
|
||||||
@ -300,16 +338,6 @@ typedef struct RedisModuleTypeMethods {
|
|||||||
int aux_save_triggers;
|
int aux_save_triggers;
|
||||||
} RedisModuleTypeMethods;
|
} 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) \
|
#define REDISMODULE_GET_API(name) \
|
||||||
RedisModule_GetApi("RedisModule_" #name, ((void **)&RedisModule_ ## name))
|
RedisModule_GetApi("RedisModule_" #name, ((void **)&RedisModule_ ## name))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user