| 1200 | } |
| 1201 | |
| 1202 | void copyCommand(client *c) { |
| 1203 | robj *o; |
| 1204 | redisDb *src, *dst; |
| 1205 | int srcid, dbid; |
| 1206 | long long expire; |
| 1207 | int j, replace = 0, delete = 0; |
| 1208 | |
| 1209 | /* Obtain source and target DB pointers |
| 1210 | * Default target DB is the same as the source DB |
| 1211 | * Parse the REPLACE option and targetDB option. */ |
| 1212 | src = c->db; |
| 1213 | dst = c->db; |
| 1214 | srcid = c->db->id; |
| 1215 | dbid = c->db->id; |
| 1216 | for (j = 3; j < c->argc; j++) { |
| 1217 | int additional = c->argc - j - 1; |
| 1218 | if (!strcasecmp(c->argv[j]->ptr,"replace")) { |
| 1219 | replace = 1; |
| 1220 | } else if (!strcasecmp(c->argv[j]->ptr, "db") && additional >= 1) { |
| 1221 | if (getIntFromObjectOrReply(c, c->argv[j+1], &dbid, NULL) != C_OK) |
| 1222 | return; |
| 1223 | |
| 1224 | if (selectDb(c, dbid) == C_ERR) { |
| 1225 | addReplyError(c,"DB index is out of range"); |
| 1226 | return; |
| 1227 | } |
| 1228 | dst = c->db; |
| 1229 | selectDb(c,srcid); /* Back to the source DB */ |
| 1230 | j++; /* Consume additional arg. */ |
| 1231 | } else { |
| 1232 | addReplyErrorObject(c,shared.syntaxerr); |
| 1233 | return; |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | if ((server.cluster_enabled == 1) && (srcid != 0 || dbid != 0)) { |
| 1238 | addReplyError(c,"Copying to another database is not allowed in cluster mode"); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | /* If the user select the same DB as |
| 1243 | * the source DB and using newkey as the same key |
| 1244 | * it is probably an error. */ |
| 1245 | robj *key = c->argv[1]; |
| 1246 | robj *newkey = c->argv[2]; |
| 1247 | if (src == dst && (sdscmp(key->ptr, newkey->ptr) == 0)) { |
| 1248 | addReplyErrorObject(c,shared.sameobjecterr); |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | /* Check if the element exists and get a reference */ |
| 1253 | o = lookupKeyWrite(c->db, key); |
| 1254 | if (!o) { |
| 1255 | addReply(c,shared.czero); |
| 1256 | return; |
| 1257 | } |
| 1258 | expire = getExpire(c->db,key); |
| 1259 |
nothing calls this directly
no test coverage detected