diff --git a/src/replication.c b/src/replication.c index a3110661e7cfd008a60c72ee2198fed863757c74..f2e55e7b42134c4be6f621cd2216fab232ad478e 100644 --- a/src/replication.c +++ b/src/replication.c @@ -2031,6 +2031,14 @@ void replicaofCommand(client *c) { } else { long port; + if (c->flags & CLIENT_SLAVE) + { + /* If a client is already a replica they cannot run this command, + * because it involves flushing all replicas (including this client) */ + addReplyError(c, "Command is not valid when client is a replica."); + return; + } + if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != C_OK)) return;