Modules hooks: fix define / linker issues. Implement one test event.

This commit is contained in:
antirez 2019-10-22 10:44:18 +02:00
parent d54652682d
commit 019ac37e9c
4 changed files with 42 additions and 37 deletions

View File

@ -33,9 +33,6 @@
#include <dlfcn.h>
#include <sys/wait.h>
#define REDISMODULE_CORE 1
#include "redismodule.h"
/* --------------------------------------------------------------------------
* Private data structures used by the modules system. Those are data
* structures that are never exposed to Redis Modules, if not as void
@ -5769,7 +5766,7 @@ void moduleFireServerEvent(uint64_t eid, int subid, void *data) {
void *moduledata = NULL;
struct moduleClientInfoV1 civ1;
if (eid == REDISMODULE_EVENT_ID_CLIENT_CHANGE) {
if (eid == REDISMODULE_EVENT_CLIENT_CHANGE) {
modulePopulateClientInfoStructure(&civ1,data,
el->event.dataver);
}

View File

@ -827,9 +827,11 @@ void clientAcceptHandler(connection *conn) {
}
server.stat_numconnections++;
moduleFireServerEvent(REDISMODULE_EVENT_CLIENT_CHANGE,
REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED,
c);
}
#define MAX_ACCEPTS_PER_CALL 1000
static void acceptCommonHandler(connection *conn, int flags, char *ip) {
client *c;

View File

@ -163,73 +163,76 @@ typedef uint64_t RedisModuleTimerID;
#define REDISMODULE_OPTIONS_HANDLE_IO_ERRORS (1<<0)
/* Server events definitions. */
#define REDISMODULE_EVENT_ID_REPLICATION_ROLE_CHANGED 0
#define REDISMODULE_EVENT_ID_PERSISTENCE 1
#define REDISMODULE_EVENT_ID_FLUSHDB 2
#define REDISMODULE_EVENT_ID_LOADING 3
#define REDISMODULE_EVENT_ID_CLIENT_CHANGE 4
#define REDISMODULE_EVENT_ID_SHUTDOWN 5
#define REDISMODULE_EVENT_ID_REPLICA_CHANGE 6
#define REDISMODULE_EVENT_ID_MASTER_LINK_CHANGE 7
#define REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED 0
#define REDISMODULE_EVENT_PERSISTENCE 1
#define REDISMODULE_EVENT_FLUSHDB 2
#define REDISMODULE_EVENT_LOADING 3
#define REDISMODULE_EVENT_CLIENT_CHANGE 4
#define REDISMODULE_EVENT_SHUTDOWN 5
#define REDISMODULE_EVENT_REPLICA_CHANGE 6
#define REDISMODULE_EVENT_MASTER_LINK_CHANGE 7
typedef struct RedisModuleEvent {
uint64_t id; /* REDISMODULE_EVENT_ID_... defines. */
uint64_t id; /* REDISMODULE_EVENT_... defines. */
uint64_t dataver; /* Version of the structure we pass as 'data'. */
} RedisModuleEvent;
RedisModuleEvent
struct RedisModuleCtx;
typedef int (*RedisModuleEventCallback)(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64_t subevent, void *data);
static RedisModuleEvent
RedisModuleEvent_ReplicationRoleChanged = {
REDISMODULE_EVENT_ID_REPLICATION_ROLE_CHANGED,
REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED,
1
},
RedisModuleEvent_Persistence = {
REDISMODULE_EVENT_ID_PERSISTENCE,
REDISMODULE_EVENT_PERSISTENCE,
1
},
RedisModuleEvent_FlushDB = {
REDISMODULE_EVENT_ID_FLUSHDB,
REDISMODULE_EVENT_FLUSHDB,
1
},
RedisModuleEvent_Loading = {
REDISMODULE_EVENT_ID_LOADING,
REDISMODULE_EVENT_LOADING,
1
},
RedisModuleEvent_ClientChange = {
REDISMODULE_EVENT_ID_CLIENT_CHANGE,
REDISMODULE_EVENT_CLIENT_CHANGE,
1
},
RedisModuleEvent_Shutdown = {
REDISMODULE_EVENT_ID_SHUTDOWN,
REDISMODULE_EVENT_SHUTDOWN,
1
},
RedisModuleEvent_ReplicaChange = {
REDISMODULE_EVENT_ID_REPLICA_CHANGE,
REDISMODULE_EVENT_REPLICA_CHANGE,
1
},
RedisModuleEvent_MasterLinkChange = {
REDISMODULE_EVENT_ID_MASTER_LINK_CHANGE,
REDISMODULE_EVENT_MASTER_LINK_CHANGE,
1
};
typedef int (*RedisModuleEventCallback)(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64_t subevent, void *data);
/* Those are values that are used for the 'subevent' callback argument. */
#define REDISMODULE_EVENT_PERSISTENCE_RDB_START 0
#define REDISMODULE_EVENT_PERSISTENCE_RDB_END 1
#define REDISMODULE_EVENT_PERSISTENCE_AOF_START 2
#define REDISMODULE_EVENT_PERSISTENCE_AOF_END 3
#define REDISMODULE_SUBEVENT_PERSISTENCE_RDB_START 0
#define REDISMODULE_SUBEVENT_PERSISTENCE_RDB_END 1
#define REDISMODULE_SUBEVENT_PERSISTENCE_AOF_START 2
#define REDISMODULE_SUBEVENT_PERSISTENCE_AOF_END 3
#define REDISMODULE_EVENT_LOADING_START 0
#define REDISMODULE_EVENT_LOADING_END 1
#define REDISMODULE_SUBEVENT_LOADING_RDB_START 0
#define REDISMODULE_SUBEVENT_LOADING_RDB_END 1
#define REDISMODULE_SUBEVENT_LOADING_AOF_START 2
#define REDISMODULE_SUBEVENT_LOADING_AOF_END 3
#define REDISMODULE_EVENT_CLIENT_CHANGE_CONNECTED 0
#define REDISMODULE_EVENT_CLIENT_CHANGE_DISCONNECTED 1
#define REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED 0
#define REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED 1
#define REDISMODULE_EVENT_MASTER_LINK_UP 0
#define REDISMODULE_EVENT_MASTER_LINK_DOWN 1
#define REDISMODULE_SUBEVENT_MASTER_LINK_UP 0
#define REDISMODULE_SUBEVENT_MASTER_LINK_DOWN 1
#define REDISMODULE_EVENT_REPLICA_CHANGE_CONNECTED 0
#define REDISMODULE_EVENT_REPLICA_CHANGE_DISCONNECTED 1
#define REDISMODULE_SUBEVENT_REPLICA_CHANGE_CONNECTED 0
#define REDISMODULE_SUBEVENT_REPLICA_CHANGE_DISCONNECTED 1
/* RedisModuleClientInfo flags. */
#define REDISMODULE_CLIENTINFO_FLAG_SSL (1<<0)

View File

@ -68,6 +68,9 @@ typedef long long mstime_t; /* millisecond time type. */
#include "rax.h" /* Radix tree */
#include "connection.h" /* Connection abstraction */
#define REDISMODULE_CORE 1
#include "redismodule.h" /* Redis modules API defines. */
/* Following includes allow test functions to be called from Redis main() */
#include "zipmap.h"
#include "sha1.h"