diff --git a/src/sentinel.c b/src/sentinel.c index edf430ef06ab421138daed4ee55f24fc45699c7c..567583ea72b7cf0f158022d0aec203ee545e5658 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? */