From 365094028bf6dc311c0246f68e6bf40944136e9b Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 14 Mar 2014 11:04:54 +0100 Subject: [PATCH] Sentinel: fake PUBLISH command to receive HELLO messages. Now the way HELLO messages are received is unified. Now it is no longer needed for Sentinels to converge to the higher configuration for a master to be able to chat via some Redis instance, the are able to directly exchanges configurations. Note that this commit does not include the (trivial) change needed to send HELLO messages to Sentinel instances as well, since for an error I committed the change in the previous commit that refactored hello messages processing into a separated function. --- src/sentinel.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sentinel.c b/src/sentinel.c index edf430ef..567583ea 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -371,6 +371,7 @@ dictType leaderVotesDictType = { void sentinelCommand(redisClient *c); void sentinelInfoCommand(redisClient *c); void sentinelSetCommand(redisClient *c); +void sentinelPublishCommand(redisClient *c); struct redisCommand sentinelcmds[] = { {"ping",pingCommand,1,"",0,NULL,0,0,0,0,0}, @@ -379,6 +380,7 @@ struct redisCommand sentinelcmds[] = { {"unsubscribe",unsubscribeCommand,-1,"",0,NULL,0,0,0,0,0}, {"psubscribe",psubscribeCommand,-2,"",0,NULL,0,0,0,0,0}, {"punsubscribe",punsubscribeCommand,-1,"",0,NULL,0,0,0,0,0}, + {"publish",sentinelPublishCommand,3,"",0,NULL,0,0,0,0,0}, {"info",sentinelInfoCommand,-1,"",0,NULL,0,0,0,0,0}, {"shutdown",shutdownCommand,-1,"",0,NULL,0,0,0,0,0} }; @@ -2739,6 +2741,21 @@ badfmt: /* Bad format errors */ value, option); } +/* Our fake PUBLISH command: it is actually useful only to receive hello messages + * from the other sentinel instances, and publishing to a channel other than + * SENTINEL_HELLO_CHANNEL is forbidden. + * + * Because we have a Sentinel PUBLISH, the code to send hello messages is the same + * for all the three kind of instances: masters, slaves, sentinels. */ +void sentinelPublishCommand(redisClient *c) { + if (strcmp(c->argv[1]->ptr,SENTINEL_HELLO_CHANNEL)) { + addReplyError(c, "Only HELLO messages are accepted by Sentinel instances."); + return; + } + sentinelProcessHelloMessage(c->argv[2]->ptr,sdslen(c->argv[2]->ptr)); + addReplyLongLong(c,1); +} + /* ===================== SENTINEL availability checks ======================= */ /* Is this instance down from our point of view? */