diff --git a/src/module.c b/src/module.c index 0cfc92416..63d2ac1bb 100644 --- a/src/module.c +++ b/src/module.c @@ -33,9 +33,6 @@ #include #include -#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); } diff --git a/src/networking.c b/src/networking.c index ddfe4d8e3..c20c13e9a 100644 --- a/src/networking.c +++ b/src/networking.c @@ -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; diff --git a/src/redismodule.h b/src/redismodule.h index 0bc6d2c3e..02cfa9586 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -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) diff --git a/src/server.h b/src/server.h index a427ef373..97672d727 100644 --- a/src/server.h +++ b/src/server.h @@ -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"