MIGRATE host port key dbid timeout [COPY | REPLACE | AUTH password | * AUTH2 username password] * * On in the multiple keys form: * * MIGRATE host port "" dbid timeout [COPY | REPLACE | AUTH password | * AUTH2 username password] KEYS key1 key2 ... keyN */
| 5480 | * MIGRATE host port "" dbid timeout [COPY | REPLACE | AUTH password | |
| 5481 | * AUTH2 username password] KEYS key1 key2 ... keyN */ |
| 5482 | void migrateCommand(client *c) { |
| 5483 | migrateCachedSocket *cs; |
| 5484 | int copy = 0, replace = 0, j; |
| 5485 | char *username = NULL; |
| 5486 | char *password = NULL; |
| 5487 | long timeout; |
| 5488 | long dbid; |
| 5489 | robj_roptr *ov = NULL; /* Objects to migrate. */ |
| 5490 | robj **kv = NULL; /* Key names. */ |
| 5491 | robj **newargv = NULL; /* Used to rewrite the command as DEL ... keys ... */ |
| 5492 | rio cmd, payload; |
| 5493 | int may_retry = 1; |
| 5494 | int write_error = 0; |
| 5495 | int argv_rewritten = 0; |
| 5496 | |
| 5497 | /* To support the KEYS option we need the following additional state. */ |
| 5498 | int first_key = 3; /* Argument index of the first key. */ |
| 5499 | int num_keys = 1; /* By default only migrate the 'key' argument. */ |
| 5500 | |
| 5501 | /* Parse additional options */ |
| 5502 | for (j = 6; j < c->argc; j++) { |
| 5503 | int moreargs = (c->argc-1) - j; |
| 5504 | if (!strcasecmp(szFromObj(c->argv[j]),"copy")) { |
| 5505 | copy = 1; |
| 5506 | } else if (!strcasecmp(szFromObj(c->argv[j]),"replace")) { |
| 5507 | replace = 1; |
| 5508 | } else if (!strcasecmp(szFromObj(c->argv[j]),"auth")) { |
| 5509 | if (!moreargs) { |
| 5510 | addReplyErrorObject(c,shared.syntaxerr); |
| 5511 | return; |
| 5512 | } |
| 5513 | j++; |
| 5514 | password = szFromObj(c->argv[j]); |
| 5515 | redactClientCommandArgument(c,j); |
| 5516 | } else if (!strcasecmp(szFromObj(c->argv[j]),"auth2")) { |
| 5517 | if (moreargs < 2) { |
| 5518 | addReply(c,shared.syntaxerr); |
| 5519 | return; |
| 5520 | } |
| 5521 | username = szFromObj(c->argv[++j]); |
| 5522 | redactClientCommandArgument(c,j); |
| 5523 | password = szFromObj(c->argv[++j]); |
| 5524 | redactClientCommandArgument(c,j); |
| 5525 | } else if (!strcasecmp(szFromObj(c->argv[j]),"keys")) { |
| 5526 | if (sdslen(szFromObj(c->argv[3])) != 0) { |
| 5527 | addReplyError(c, |
| 5528 | "When using MIGRATE KEYS option, the key argument" |
| 5529 | " must be set to the empty string"); |
| 5530 | return; |
| 5531 | } |
| 5532 | first_key = j+1; |
| 5533 | num_keys = c->argc - j - 1; |
| 5534 | break; /* All the remaining args are keys. */ |
| 5535 | } else { |
| 5536 | addReplyErrorObject(c,shared.syntaxerr); |
| 5537 | return; |
| 5538 | } |
| 5539 | } |
nothing calls this directly
no test coverage detected