Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
28210760
Commit
28210760
authored
Sep 19, 2018
by
antirez
Browse files
Module cluster flags: use RM_SetClusterFlags() in the example.
parent
18c5ab93
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
28210760
...
...
@@ -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
)
...
...
src/modules/hellocluster.c
View file @
28210760
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment