From c9b51c96a4f4d0ea80e8f5727b3155982aeda5b6 Mon Sep 17 00:00:00 2001 From: Tom Gabsow Date: Thu, 18 Jun 2026 09:52:29 +0300 Subject: [PATCH 1/2] MOD-16382 Vendor RedisModuleEvent_ClusterTopologyChange (event id 20) Mirror the new server event from redis/redis#15350 so modules built against this SDK can subscribe to cluster topology change notifications. The event carries no data payload (the module reads cluster info via the existing APIs), so only the event id and subevent constants are vendored. Relates-to: RED-148990 Co-Authored-By: Claude Opus 4.8 --- redismodule.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/redismodule.h b/redismodule.h index 7f2e448..20d0ace 100644 --- a/redismodule.h +++ b/redismodule.h @@ -520,7 +520,8 @@ typedef void (*RedisModuleEventLoopOneShotFunc)(void *user_data); #define REDISMODULE_EVENT_KEY 17 #define REDISMODULE_EVENT_CLUSTER_SLOT_MIGRATION 18 #define REDISMODULE_EVENT_CLUSTER_SLOT_MIGRATION_TRIM 19 -#define _REDISMODULE_EVENT_NEXT 20 /* Next event flag, should be updated if a new event added. */ +#define REDISMODULE_EVENT_CLUSTER_TOPOLOGY_CHANGE 20 +#define _REDISMODULE_EVENT_NEXT 21 /* Next event flag, should be updated if a new event added. */ typedef struct RedisModuleEvent { uint64_t id; /* REDISMODULE_EVENT_... defines. */ @@ -639,6 +640,10 @@ static const RedisModuleEvent RedisModuleEvent_ClusterSlotMigrationTrim = { REDISMODULE_EVENT_CLUSTER_SLOT_MIGRATION_TRIM, 1 + }, + RedisModuleEvent_ClusterTopologyChange = { + REDISMODULE_EVENT_CLUSTER_TOPOLOGY_CHANGE, + 1 }; /* Those are values that are used for the 'subevent' callback argument. */ @@ -731,6 +736,11 @@ static const RedisModuleEvent #define REDISMODULE_SUBEVENT_CLUSTER_SLOT_MIGRATION_TRIM_BACKGROUND 2 #define _REDISMODULE_SUBEVENT_CLUSTER_SLOT_MIGRATION_TRIM_NEXT 3 +#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_STARTUP 0 +#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_TOPOLOGY_CHANGED 1 +#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_ROLE_CHANGED 2 +#define _REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_NEXT 3 + /* RedisModuleClientInfo flags. */ #define REDISMODULE_CLIENTINFO_FLAG_SSL (1<<0) #define REDISMODULE_CLIENTINFO_FLAG_PUBSUB (1<<1) From ec4c7ebc2f8546abb180eb3cb174a77ae604c338 Mon Sep 17 00:00:00 2001 From: Tom Gabsow Date: Wed, 24 Jun 2026 21:34:06 +0300 Subject: [PATCH 2/2] MOD-16382 Vendor cluster topology-change reason flags (change_flags bitmask) Mirror the core redismodule.h: RedisModuleEvent_ClusterTopologyChange carries a RedisModuleClusterTopologyChangeInfo { uint64_t change_flags } reason bitmask (REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_SLOT / _ROLE / _STATE / _NODE) so consumers can rebuild connections only when the set of primaries may have changed (NODE/ROLE/STATE) and do a cheap slot-map update on an in-place reshard (SLOT only). Co-Authored-By: Claude Opus 4.8 --- redismodule.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/redismodule.h b/redismodule.h index 20d0ace..cd73295 100644 --- a/redismodule.h +++ b/redismodule.h @@ -736,10 +736,8 @@ static const RedisModuleEvent #define REDISMODULE_SUBEVENT_CLUSTER_SLOT_MIGRATION_TRIM_BACKGROUND 2 #define _REDISMODULE_SUBEVENT_CLUSTER_SLOT_MIGRATION_TRIM_NEXT 3 -#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_STARTUP 0 -#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_TOPOLOGY_CHANGED 1 -#define REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_ROLE_CHANGED 2 -#define _REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_NEXT 3 +/* RedisModuleEvent_ClusterTopologyChange has no meaningful subevent. */ +#define _REDISMODULE_SUBEVENT_CLUSTER_TOPOLOGY_CHANGE_NEXT 0 /* RedisModuleClientInfo flags. */ #define REDISMODULE_CLIENTINFO_FLAG_SSL (1<<0) @@ -905,6 +903,26 @@ typedef struct RedisModuleClusterSlotMigrationTrimInfo { #define RedisModuleClusterSlotMigrationTrimInfo RedisModuleClusterSlotMigrationTrimInfoV1 +/* Reason flags reported in RedisModuleClusterTopologyChangeInfo.change_flags. + * More than one bit may be set when several changes were collapsed into a + * single (debounced) RedisModuleEvent_ClusterTopologyChange notification. */ +#define REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_SLOT (1<<0) /* Slot ownership changed. */ +#define REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_ROLE (1<<1) /* A node changed its primary/replica role. */ +#define REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_STATE (1<<2) /* The cluster OK/FAIL state changed. */ +#define REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_NODE (1<<3) /* A node joined or left the cluster. */ + +#define REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_INFO_VERSION 1 + +typedef struct RedisModuleClusterTopologyChangeInfo { + uint64_t version; /* Not used since this structure is never passed + from the module to the core right now. Here + for future compatibility. */ + uint64_t change_flags; /* Bitmask of REDISMODULE_CLUSTER_TOPOLOGY_CHANGE_FLAG_* + reasons that contributed to this notification. */ +} RedisModuleClusterTopologyChangeInfoV1; + +#define RedisModuleClusterTopologyChangeInfo RedisModuleClusterTopologyChangeInfoV1 + typedef enum { REDISMODULE_ACL_LOG_AUTH = 0, /* Authentication failure */ REDISMODULE_ACL_LOG_CMD, /* Command authorization failure */