Add masters/replicas options to redis-cli --cluster call command (#6491)

* Add master/slave option in --cluster call command

* Update src/redis-cli.c

* Update src/redis-cli.c

Co-authored-by: Itamar Haber <itamar@redislabs.com>
(cherry picked from commit f22f64f0db)
This commit is contained in:
Thandayuthapani 2020-09-02 18:53:49 +05:30 committed by Oran Agra
parent 9b718d41f0
commit b983015dd4

View File

@ -125,6 +125,8 @@
#define CLUSTER_MANAGER_CMD_FLAG_COLOR 1 << 8 #define CLUSTER_MANAGER_CMD_FLAG_COLOR 1 << 8
#define CLUSTER_MANAGER_CMD_FLAG_CHECK_OWNERS 1 << 9 #define CLUSTER_MANAGER_CMD_FLAG_CHECK_OWNERS 1 << 9
#define CLUSTER_MANAGER_CMD_FLAG_FIX_WITH_UNREACHABLE_MASTERS 1 << 10 #define CLUSTER_MANAGER_CMD_FLAG_FIX_WITH_UNREACHABLE_MASTERS 1 << 10
#define CLUSTER_MANAGER_CMD_FLAG_MASTERS_ONLY 1 << 11
#define CLUSTER_MANAGER_CMD_FLAG_SLAVES_ONLY 1 << 12
#define CLUSTER_MANAGER_OPT_GETFRIENDS 1 << 0 #define CLUSTER_MANAGER_OPT_GETFRIENDS 1 << 0
#define CLUSTER_MANAGER_OPT_COLD 1 << 1 #define CLUSTER_MANAGER_OPT_COLD 1 << 1
@ -1543,6 +1545,12 @@ static int parseOptions(int argc, char **argv) {
i = j; i = j;
} else if (!strcmp(argv[i],"--cluster") && lastarg) { } else if (!strcmp(argv[i],"--cluster") && lastarg) {
usage(); usage();
} else if ((!strcmp(argv[i],"--cluster-only-masters"))) {
config.cluster_manager_command.flags |=
CLUSTER_MANAGER_CMD_FLAG_MASTERS_ONLY;
} else if ((!strcmp(argv[i],"--cluster-only-replicas"))) {
config.cluster_manager_command.flags |=
CLUSTER_MANAGER_CMD_FLAG_SLAVES_ONLY;
} else if (!strcmp(argv[i],"--cluster-replicas") && !lastarg) { } else if (!strcmp(argv[i],"--cluster-replicas") && !lastarg) {
config.cluster_manager_command.replicas = atoi(argv[++i]); config.cluster_manager_command.replicas = atoi(argv[++i]);
} else if (!strcmp(argv[i],"--cluster-master-id") && !lastarg) { } else if (!strcmp(argv[i],"--cluster-master-id") && !lastarg) {
@ -2320,7 +2328,7 @@ clusterManagerCommandDef clusterManagerCommands[] = {
"new_host:new_port existing_host:existing_port", "slave,master-id <arg>"}, "new_host:new_port existing_host:existing_port", "slave,master-id <arg>"},
{"del-node", clusterManagerCommandDeleteNode, 2, "host:port node_id",NULL}, {"del-node", clusterManagerCommandDeleteNode, 2, "host:port node_id",NULL},
{"call", clusterManagerCommandCall, -2, {"call", clusterManagerCommandCall, -2,
"host:port command arg arg .. arg", NULL}, "host:port command arg arg .. arg", "only-masters,only-replicas"},
{"set-timeout", clusterManagerCommandSetTimeout, 2, {"set-timeout", clusterManagerCommandSetTimeout, 2,
"host:port milliseconds", NULL}, "host:port milliseconds", NULL},
{"import", clusterManagerCommandImport, 1, "host:port", {"import", clusterManagerCommandImport, 1, "host:port",
@ -6423,6 +6431,10 @@ static int clusterManagerCommandCall(int argc, char **argv) {
listRewind(cluster_manager.nodes, &li); listRewind(cluster_manager.nodes, &li);
while ((ln = listNext(&li)) != NULL) { while ((ln = listNext(&li)) != NULL) {
clusterManagerNode *n = ln->value; clusterManagerNode *n = ln->value;
if ((config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_MASTERS_ONLY)
&& (n->replicate != NULL)) continue; // continue if node is slave
if ((config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_SLAVES_ONLY)
&& (n->replicate == NULL)) continue; // continue if node is master
if (!n->context && !clusterManagerNodeConnect(n)) continue; if (!n->context && !clusterManagerNodeConnect(n)) continue;
redisReply *reply = NULL; redisReply *reply = NULL;
redisAppendCommandArgv(n->context, argc, (const char **) argv, argvlen); redisAppendCommandArgv(n->context, argc, (const char **) argv, argvlen);
@ -8196,4 +8208,3 @@ int main(int argc, char **argv) {
return noninteractive(argc,convertToSds(argc,argv)); return noninteractive(argc,convertToSds(argc,argv));
} }
} }