@@ -77,6 +77,7 @@ void PingReceiver(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, cons
7777 RedisModule_Log (ctx ,"notice" ,"PING (type %d) RECEIVED from %.*s: '%.*s'" ,
7878 type ,REDISMODULE_NODE_ID_LEN ,sender_id ,(int )len , payload );
7979 RedisModule_SendClusterMessage (ctx ,NULL ,MSGTYPE_PONG ,(unsigned char * )"Ohi!" ,4 );
80+ RedisModule_Call (ctx , "INCR" , "c" , "pings_received" );
8081}
8182
8283/* Callback for message MSGTYPE_PONG. */
@@ -102,6 +103,15 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
102103 ListCommand_RedisCommand ,"readonly" ,0 ,0 ,0 ) == REDISMODULE_ERR )
103104 return REDISMODULE_ERR ;
104105
106+ /* Disable Redis Cluster sharding and redirections. This way every node
107+ * will be able to access every possible key, regardless of the hash slot.
108+ * This way the PING message handler will be able to increment a specific
109+ * variable. Normally you do that in order for the distributed system
110+ * you create as a module to have total freedom in the keyspace
111+ * manipulation. */
112+ RedisModule_SetClusterFlags (ctx ,REDISMODULE_CLUSTER_FLAG_NO_REDIRECTION );
113+
114+ /* Register our handlers for different message types. */
105115 RedisModule_RegisterClusterMessageReceiver (ctx ,MSGTYPE_PING ,PingReceiver );
106116 RedisModule_RegisterClusterMessageReceiver (ctx ,MSGTYPE_PONG ,PongReceiver );
107117 return REDISMODULE_OK ;
0 commit comments