From 39f9f449b08b5838144160dcea1b9e0b5923e43b Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 10 Jan 2014 15:16:55 +0100 Subject: [PATCH] Sentinel: SENTINEL MONITOR command implemented. It allows to add new masters to monitor at runtime. --- src/sentinel.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/sentinel.c b/src/sentinel.c index 4966a1dbd..6c328356c 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2486,6 +2486,40 @@ void sentinelCommand(redisClient *c) { if (c->argc != 2) goto numargserr; sentinelPendingScriptsCommand(c); + } else if (!strcasecmp(c->argv[1]->ptr,"monitor")) { + /* SENTINEL MONITOR */ + long quorum, port; + char buf[32]; + + if (c->argc != 6) goto numargserr; + if (getLongFromObjectOrReply(c,c->argv[5],&quorum,"Invalid quorum") + != REDIS_OK) return; + if (getLongFromObjectOrReply(c,c->argv[4],&port,"Invalid port") + != REDIS_OK) return; + /* Make sure the IP field is actually a valid IP before passing it + * to createSentinelRedisInstance(), otherwise we may trigger a + * DNS lookup at runtime. */ + if (anetResolveIP(NULL,c->argv[3]->ptr,buf,sizeof(buf)) == ANET_ERR) { + addReplyError(c,"Invalid IP address specified"); + return; + } + if (createSentinelRedisInstance(c->argv[2]->ptr,SRI_MASTER, + c->argv[3]->ptr,port,quorum,NULL) == NULL) + { + switch(errno) { + case EBUSY: + addReplyError(c,"Duplicated master name"); + break; + case EINVAL: + addReplyError(c,"Invalid port number"); + break; + default: + addReplyError(c,"Unspecified error adding the instance"); + break; + } + } else { + addReply(c,shared.ok); + } } else { addReplyErrorFormat(c,"Unknown sentinel subcommand '%s'", (char*)c->argv[1]->ptr);