Sentinel: SENTINEL MONITOR command implemented.
It allows to add new masters to monitor at runtime.
This commit is contained in:
parent
774f0bd45e
commit
39f9f449b0
@ -2486,6 +2486,40 @@ void sentinelCommand(redisClient *c) {
|
|||||||
|
|
||||||
if (c->argc != 2) goto numargserr;
|
if (c->argc != 2) goto numargserr;
|
||||||
sentinelPendingScriptsCommand(c);
|
sentinelPendingScriptsCommand(c);
|
||||||
|
} else if (!strcasecmp(c->argv[1]->ptr,"monitor")) {
|
||||||
|
/* SENTINEL MONITOR <name> <ip> <port> <quorum> */
|
||||||
|
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 {
|
} else {
|
||||||
addReplyErrorFormat(c,"Unknown sentinel subcommand '%s'",
|
addReplyErrorFormat(c,"Unknown sentinel subcommand '%s'",
|
||||||
(char*)c->argv[1]->ptr);
|
(char*)c->argv[1]->ptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user