From 4079f799745bd9e030b2c75d29373e6a13a0f015 Mon Sep 17 00:00:00 2001 From: Huang Zhw Date: Wed, 2 Jun 2021 22:30:08 +0800 Subject: [PATCH] redis-cli cluster import command may issue wrong MIGRATE command. (#8945) In clusterManagerCommandImport strcat was used to concat COPY and REPLACE, the space maybe not enough. If we use --cluster-replace but not --cluster-copy, the MIGRATE command contained COPY instead of REPLACE. (cherry picked from commit a049f6295a28a20b11eff89083e91dab0738413b) --- src/redis-cli.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 06ccf1563..3160ada46 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -6540,9 +6540,9 @@ static int clusterManagerCommandImport(int argc, char **argv) { } if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_COPY) - strcat(cmdfmt, " %s"); + cmdfmt = sdscat(cmdfmt," COPY"); if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_REPLACE) - strcat(cmdfmt, " %s"); + cmdfmt = sdscat(cmdfmt," REPLACE"); /* Use SCAN to iterate over the keys, migrating to the * right node as needed. */ @@ -6574,8 +6574,7 @@ static int clusterManagerCommandImport(int argc, char **argv) { printf("Migrating %s to %s:%d: ", key, target->ip, target->port); redisReply *r = reconnectingRedisCommand(src_ctx, cmdfmt, target->ip, target->port, - key, 0, timeout, - "COPY", "REPLACE"); + key, 0, timeout); if (!r || r->type == REDIS_REPLY_ERROR) { if (r && r->str) { clusterManagerLogErr("Source %s:%d replied with "