diff --git a/src/cluster.c b/src/cluster.c index 421e678b..ad48641e 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -5438,6 +5438,10 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in /* Set error code optimistically for the base case. */ if (error_code) *error_code = CLUSTER_REDIR_NONE; + /* Modules can turn off Redis Cluster redirection: this is useful + * when writing a module that implements a completely different + * distributed system. */ + /* We handle all the cases as if they were EXEC commands, so we have * a common code path for everything */ if (cmd->proc == execCommand) { diff --git a/src/cluster.h b/src/cluster.h index 6f9954d2..68d7af3a 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -100,6 +100,13 @@ typedef struct clusterLink { #define CLUSTERMSG_TYPE_MODULE 9 /* Module cluster API message. */ #define CLUSTERMSG_TYPE_COUNT 10 /* Total number of message types. */ +/* Flags that a module can set in order to prevent certain Redis Cluster + * features to be enabled. Useful when implementing a different distributed + * system on top of Redis Cluster message bus, using modules. */ +#define MODULE_CLUSTER_FLAG_NONE 0 +#define MODULE_CLUSTER_FLAG_NO_FAILOVER (1<<1) +#define MODULE_CLUSTER_FLAG_NO_REDIRECTION (1<<2) + /* This structure represent elements of node->fail_reports. */ typedef struct clusterNodeFailReport { struct clusterNode *node; /* Node reporting the failure condition. */ diff --git a/src/redismodule.h b/src/redismodule.h index 47ecb130..d3786564 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -117,6 +117,10 @@ #define REDISMODULE_NODE_FAIL (1<<4) #define REDISMODULE_NODE_NOFAILOVER (1<<5) +#define REDISMODULE_CLUSTER_FLAG_NONE 0 +#define REDISMODULE_CLUSTER_FLAG_NO_FAILOVER (1<<1) +#define REDISMODULE_CLUSTER_FLAG_NO_REDIRECTION (1<<2) + #define REDISMODULE_NOT_USED(V) ((void) V) /* This type represents a timer handle, and is returned when a timer is diff --git a/src/server.c b/src/server.c index db52f5fc..dee18fa6 100644 --- a/src/server.c +++ b/src/server.c @@ -1621,6 +1621,7 @@ void initServerConfig(void) { server.cluster_announce_ip = CONFIG_DEFAULT_CLUSTER_ANNOUNCE_IP; server.cluster_announce_port = CONFIG_DEFAULT_CLUSTER_ANNOUNCE_PORT; server.cluster_announce_bus_port = CONFIG_DEFAULT_CLUSTER_ANNOUNCE_BUS_PORT; + server.cluster_module_flags = MODULE_CLUSTER_FLAG_NONE; server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.next_client_id = 1; /* Client IDs, start from 1 .*/ server.loading_process_events_interval_bytes = (1024*1024*2); diff --git a/src/server.h b/src/server.h index 8b10701d..4c4c0ce5 100644 --- a/src/server.h +++ b/src/server.h @@ -1232,6 +1232,10 @@ struct redisServer { char *cluster_announce_ip; /* IP address to announce on cluster bus. */ int cluster_announce_port; /* base port to announce on cluster bus. */ int cluster_announce_bus_port; /* bus port to announce on cluster bus. */ + int cluster_module_flags; /* Set of flags that Redis modules are able + to set in order to suppress certain + native Redis Cluster features. Check the + REDISMODULE_CLUSTER_FLAG_*. */ /* Scripting */ lua_State *lua; /* The Lua interpreter. We use just one for all clients */ client *lua_client; /* The "fake client" to query Redis from Lua */