diff options
author | antirez <antirez@gmail.com> | 2018-09-19 16:17:20 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-09-19 16:17:20 +0200 |
commit | 0d6f11f4d1748d0e8b35032338a1f4d927838a49 (patch) | |
tree | 6dfc2c8f1ae1da870809ed14b7675479a9c4aaf2 | |
parent | 3213e8de921ef55896f740fb55e9469bbe2a22c4 (diff) | |
download | redis-0d6f11f4d1748d0e8b35032338a1f4d927838a49.tar.gz |
Module cluster flags: use RM_SetClusterFlags() in the example.
-rw-r--r-- | src/module.c | 1 | ||||
-rw-r--r-- | src/modules/hellocluster.c | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c index 57e7c92f3..4633a1d33 100644 --- a/src/module.c +++ b/src/module.c @@ -4151,6 +4151,7 @@ int RM_GetClusterNodeInfo(RedisModuleCtx *ctx, const char *id, char *ip, char *m * Slots informations will still be propagated across the * cluster, but without effects. */ void RM_SetClusterFlags(RedisModuleCtx *ctx, uint64_t flags) { + UNUSED(ctx); if (flags & REDISMODULE_CLUSTER_FLAG_NO_FAILOVER) server.cluster_module_flags |= CLUSTER_MODULE_FLAG_NO_FAILOVER; if (flags & REDISMODULE_CLUSTER_FLAG_NO_REDIRECTION) diff --git a/src/modules/hellocluster.c b/src/modules/hellocluster.c index da3964d04..cb78187f9 100644 --- a/src/modules/hellocluster.c +++ b/src/modules/hellocluster.c @@ -77,6 +77,7 @@ void PingReceiver(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, cons RedisModule_Log(ctx,"notice","PING (type %d) RECEIVED from %.*s: '%.*s'", type,REDISMODULE_NODE_ID_LEN,sender_id,(int)len, payload); RedisModule_SendClusterMessage(ctx,NULL,MSGTYPE_PONG,(unsigned char*)"Ohi!",4); + RedisModule_Call(ctx, "INCR", "c", "pings_received"); } /* Callback for message MSGTYPE_PONG. */ @@ -102,6 +103,15 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) ListCommand_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; + /* Disable Redis Cluster sharding and redirections. This way every node + * will be able to access every possible key, regardless of the hash slot. + * This way the PING message handler will be able to increment a specific + * variable. Normally you do that in order for the distributed system + * you create as a module to have total freedom in the keyspace + * manipulation. */ + RedisModule_SetClusterFlags(ctx,REDISMODULE_CLUSTER_FLAG_NO_REDIRECTION); + + /* Register our handlers for different message types. */ RedisModule_RegisterClusterMessageReceiver(ctx,MSGTYPE_PING,PingReceiver); RedisModule_RegisterClusterMessageReceiver(ctx,MSGTYPE_PONG,PongReceiver); return REDISMODULE_OK; |