Insert a key, handling duplicate keys according to fReplace */
| 374 | |
| 375 | /* Insert a key, handling duplicate keys according to fReplace */ |
| 376 | int dbMerge(redisDb *db, sds key, robj *val, int fReplace) |
| 377 | { |
| 378 | if (fReplace) |
| 379 | { |
| 380 | auto itr = db->find(key); |
| 381 | if (itr == nullptr) |
| 382 | return (dbAddCore(db, key, val, false /* fUpdateMvcc */) == true); |
| 383 | |
| 384 | robj_roptr old = itr.val(); |
| 385 | if (mvccFromObj(old) <= mvccFromObj(val)) |
| 386 | { |
| 387 | db->dbOverwriteCore(itr, key, val, false, true); |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | return false; |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | return (dbAddCore(db, key, val, true /* fUpdateMvcc */, true /* fAssumeNew */) == true); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /* High level Set operation. This function can be used in order to set |
| 400 | * a key, whatever it was existing or not, to a new object. |
no test coverage detected