MCPcopy Create free account
hub / github.com/F-Stack/f-stack / migrateCommand

Function migrateCommand

app/redis-6.2.6/src/cluster.c:5332–5671  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

5330 * MIGRATE host port "" dbid timeout [COPY | REPLACE | AUTH password |
5331 * AUTH2 username password] KEYS key1 key2 ... keyN */
5332void migrateCommand(client *c) {
5333 migrateCachedSocket *cs;
5334 int copy = 0, replace = 0, j;
5335 char *username = NULL;
5336 char *password = NULL;
5337 long timeout;
5338 long dbid;
5339 robj **ov = NULL; /* Objects to migrate. */
5340 robj **kv = NULL; /* Key names. */
5341 robj **newargv = NULL; /* Used to rewrite the command as DEL ... keys ... */
5342 rio cmd, payload;
5343 int may_retry = 1;
5344 int write_error = 0;
5345 int argv_rewritten = 0;
5346
5347 /* To support the KEYS option we need the following additional state. */
5348 int first_key = 3; /* Argument index of the first key. */
5349 int num_keys = 1; /* By default only migrate the 'key' argument. */
5350
5351 /* Parse additional options */
5352 for (j = 6; j < c->argc; j++) {
5353 int moreargs = (c->argc-1) - j;
5354 if (!strcasecmp(c->argv[j]->ptr,"copy")) {
5355 copy = 1;
5356 } else if (!strcasecmp(c->argv[j]->ptr,"replace")) {
5357 replace = 1;
5358 } else if (!strcasecmp(c->argv[j]->ptr,"auth")) {
5359 if (!moreargs) {
5360 addReplyErrorObject(c,shared.syntaxerr);
5361 return;
5362 }
5363 j++;
5364 password = c->argv[j]->ptr;
5365 redactClientCommandArgument(c,j);
5366 } else if (!strcasecmp(c->argv[j]->ptr,"auth2")) {
5367 if (moreargs < 2) {
5368 addReplyErrorObject(c,shared.syntaxerr);
5369 return;
5370 }
5371 username = c->argv[++j]->ptr;
5372 redactClientCommandArgument(c,j);
5373 password = c->argv[++j]->ptr;
5374 redactClientCommandArgument(c,j);
5375 } else if (!strcasecmp(c->argv[j]->ptr,"keys")) {
5376 if (sdslen(c->argv[3]->ptr) != 0) {
5377 addReplyError(c,
5378 "When using MIGRATE KEYS option, the key argument"
5379 " must be set to the empty string");
5380 return;
5381 }
5382 first_key = j+1;
5383 num_keys = c->argc - j - 1;
5384 break; /* All the remaining args are keys. */
5385 } else {
5386 addReplyErrorObject(c,shared.syntaxerr);
5387 return;
5388 }
5389 }

Callers

nothing calls this directly

Calls 15

strcasecmpFunction · 0.85
addReplyErrorObjectFunction · 0.85
sdslenFunction · 0.85
addReplyErrorFunction · 0.85
getLongFromObjectOrReplyFunction · 0.85
zreallocFunction · 0.85
lookupKeyReadFunction · 0.85
addReplySdsFunction · 0.85
sdsnewFunction · 0.85
migrateGetSocketFunction · 0.85
rioInitWithBufferFunction · 0.85

Tested by

no test coverage detected