| 1529 | } |
| 1530 | |
| 1531 | void moveCommand(client *c) { |
| 1532 | robj *o; |
| 1533 | redisDb *src, *dst; |
| 1534 | int srcid, dbid; |
| 1535 | |
| 1536 | if (g_pserver->cluster_enabled) { |
| 1537 | addReplyError(c,"MOVE is not allowed in cluster mode"); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | /* Obtain source and target DB pointers */ |
| 1542 | src = c->db; |
| 1543 | srcid = c->db->id; |
| 1544 | |
| 1545 | if (getIntFromObjectOrReply(c, c->argv[2], &dbid, NULL) != C_OK) |
| 1546 | return; |
| 1547 | |
| 1548 | if (selectDb(c,dbid) == C_ERR) { |
| 1549 | addReplyError(c,"DB index is out of range"); |
| 1550 | return; |
| 1551 | } |
| 1552 | dst = c->db; |
| 1553 | selectDb(c,srcid); /* Back to the source DB */ |
| 1554 | |
| 1555 | /* If the user is moving using as target the same |
| 1556 | * DB as the source DB it is probably an error. */ |
| 1557 | if (src == dst) { |
| 1558 | addReplyErrorObject(c,shared.sameobjecterr); |
| 1559 | return; |
| 1560 | } |
| 1561 | |
| 1562 | /* Check if the element exists and get a reference */ |
| 1563 | o = lookupKeyWrite(c->db,c->argv[1]); |
| 1564 | if (!o) { |
| 1565 | addReply(c,shared.czero); |
| 1566 | return; |
| 1567 | } |
| 1568 | |
| 1569 | /* Return zero if the key already exists in the target DB */ |
| 1570 | if (lookupKeyWrite(dst,c->argv[1]) != NULL) { |
| 1571 | addReply(c,shared.czero); |
| 1572 | return; |
| 1573 | } |
| 1574 | |
| 1575 | incrRefCount(o); |
| 1576 | bool fExpire = o->FExpires(); |
| 1577 | long long whenT = o->expire.when(); |
| 1578 | dbDelete(src,c->argv[1]); |
| 1579 | g_pserver->dirty++; |
| 1580 | |
| 1581 | o->SetFExpires(fExpire); |
| 1582 | dbAddCore(dst, szFromObj(c->argv[1]), o, true /*fUpdateMvcc*/, true /*fAssumeNew*/, nullptr, true /*fValExpires*/); |
| 1583 | serverAssert(whenT == o->expire.when()); // add/delete must not modify the expire time |
| 1584 | |
| 1585 | signalModifiedKey(c,src,c->argv[1]); |
| 1586 | signalModifiedKey(c,dst,c->argv[1]); |
| 1587 | notifyKeyspaceEvent(NOTIFY_GENERIC, |
| 1588 | "move_from",c->argv[1],src->id); |
nothing calls this directly
no test coverage detected