diff --git a/src/replication.cpp b/src/replication.cpp index dae37fc72..768a53f0c 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -3151,15 +3151,46 @@ void replicaofCommand(client *c) { return; } - /* The special host/port combination "NO" "ONE" turns the instance - * into a master. Otherwise the new master address is set. */ - if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"no") && + if (c->argc > 3) { + if (c->argc != 4) { + addReplyError(c, "Invalid arguments"); + return; + } + if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"remove")) { + listIter li; + listNode *ln; + bool fRemoved = false; + long port; + string2l(szFromObj(c->argv[3]), sdslen(szFromObj(c->argv[3])), &port); + LRestart: + listRewind(g_pserver->masters, &li); + while ((ln = listNext(&li))) { + redisMaster *mi = (redisMaster*)listNodeValue(ln); + if (mi->masterport != port) + continue; + if (sdscmp(szFromObj(c->argv[2]), mi->masterhost) == 0) { + replicationUnsetMaster(mi); + fRemoved = true; + goto LRestart; + } + } + if (!fRemoved) { + addReplyError(c, "Master not found"); + return; + } else if (listLength(g_pserver->masters) == 0) { + goto LLogNoMaster; + } + } + } else if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"no") && !strcasecmp((const char*)ptrFromObj(c->argv[2]),"one")) { + /* The special host/port combination "NO" "ONE" turns the instance + * into a master. Otherwise the new master address is set. */ if (listLength(g_pserver->masters)) { while (listLength(g_pserver->masters)) { replicationUnsetMaster((redisMaster*)listNodeValue(listFirst(g_pserver->masters))); } + LLogNoMaster: sds client = catClientInfoString(sdsempty(),c); serverLog(LL_NOTICE,"MASTER MODE enabled (user request from '%s')", client); diff --git a/src/server.cpp b/src/server.cpp index 4fa6ce725..c197df741 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -768,7 +768,7 @@ struct redisCommand redisCommandTable[] = { "admin no-script ok-stale", 0,NULL,0,0,0,0,0,0}, - {"replicaof",replicaofCommand,3, + {"replicaof",replicaofCommand,-3, "admin no-script ok-stale", 0,NULL,0,0,0,0,0,0},