@@ -3151,15 +3151,46 @@ void replicaofCommand(client *c) {
3151
3151
return ;
3152
3152
}
3153
3153
3154
- /* The special host/port combination "NO" "ONE" turns the instance
3155
- * into a master. Otherwise the new master address is set. */
3156
- if (!strcasecmp ((const char *)ptrFromObj (c->argv [1 ])," no" ) &&
3154
+ if (c->argc > 3 ) {
3155
+ if (c->argc != 4 ) {
3156
+ addReplyError (c, " Invalid arguments" );
3157
+ return ;
3158
+ }
3159
+ if (!strcasecmp ((const char *)ptrFromObj (c->argv [1 ])," remove" )) {
3160
+ listIter li;
3161
+ listNode *ln;
3162
+ bool fRemoved = false ;
3163
+ long port;
3164
+ string2l (szFromObj (c->argv [3 ]), sdslen (szFromObj (c->argv [3 ])), &port);
3165
+ LRestart:
3166
+ listRewind (g_pserver->masters , &li);
3167
+ while ((ln = listNext (&li))) {
3168
+ redisMaster *mi = (redisMaster*)listNodeValue (ln);
3169
+ if (mi->masterport != port)
3170
+ continue ;
3171
+ if (sdscmp (szFromObj (c->argv [2 ]), mi->masterhost ) == 0 ) {
3172
+ replicationUnsetMaster (mi);
3173
+ fRemoved = true ;
3174
+ goto LRestart;
3175
+ }
3176
+ }
3177
+ if (!fRemoved ) {
3178
+ addReplyError (c, " Master not found" );
3179
+ return ;
3180
+ } else if (listLength (g_pserver->masters ) == 0 ) {
3181
+ goto LLogNoMaster;
3182
+ }
3183
+ }
3184
+ } else if (!strcasecmp ((const char *)ptrFromObj (c->argv [1 ])," no" ) &&
3157
3185
!strcasecmp ((const char *)ptrFromObj (c->argv [2 ])," one" )) {
3186
+ /* The special host/port combination "NO" "ONE" turns the instance
3187
+ * into a master. Otherwise the new master address is set. */
3158
3188
if (listLength (g_pserver->masters )) {
3159
3189
while (listLength (g_pserver->masters ))
3160
3190
{
3161
3191
replicationUnsetMaster ((redisMaster*)listNodeValue (listFirst (g_pserver->masters )));
3162
3192
}
3193
+ LLogNoMaster:
3163
3194
sds client = catClientInfoString (sdsempty (),c);
3164
3195
serverLog (LL_NOTICE," MASTER MODE enabled (user request from '%s')" ,
3165
3196
client);
0 commit comments