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

Function swapdbCommand

app/redis-6.2.6/src/db.c:1367–1395  ·  view source on GitHub ↗

SWAPDB db1 db2 */

Source from the content-addressed store, hash-verified

1365
1366/* SWAPDB db1 db2 */
1367void swapdbCommand(client *c) {
1368 int id1, id2;
1369
1370 /* Not allowed in cluster mode: we have just DB 0 there. */
1371 if (server.cluster_enabled) {
1372 addReplyError(c,"SWAPDB is not allowed in cluster mode");
1373 return;
1374 }
1375
1376 /* Get the two DBs indexes. */
1377 if (getIntFromObjectOrReply(c, c->argv[1], &id1,
1378 "invalid first DB index") != C_OK)
1379 return;
1380
1381 if (getIntFromObjectOrReply(c, c->argv[2], &id2,
1382 "invalid second DB index") != C_OK)
1383 return;
1384
1385 /* Swap... */
1386 if (dbSwapDatabases(id1,id2) == C_ERR) {
1387 addReplyError(c,"DB index is out of range");
1388 return;
1389 } else {
1390 RedisModuleSwapDbInfo si = {REDISMODULE_SWAPDBINFO_VERSION,id1,id2};
1391 moduleFireServerEvent(REDISMODULE_EVENT_SWAPDB,0,&si);
1392 server.dirty++;
1393 addReply(c,shared.ok);
1394 }
1395}
1396
1397/*-----------------------------------------------------------------------------
1398 * Expires API

Callers

nothing calls this directly

Calls 5

addReplyErrorFunction · 0.85
getIntFromObjectOrReplyFunction · 0.85
dbSwapDatabasesFunction · 0.85
moduleFireServerEventFunction · 0.85
addReplyFunction · 0.85

Tested by

no test coverage detected