MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / dbMerge

Function dbMerge

src/db.cpp:376–397  ·  view source on GitHub ↗

Insert a key, handling duplicate keys according to fReplace */

Source from the content-addressed store, hash-verified

374
375/* Insert a key, handling duplicate keys according to fReplace */
376int 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.

Callers 3

mvccrestoreCommandFunction · 0.85
processJobMethod · 0.85
flushQueuedKeysMethod · 0.85

Calls 5

dbAddCoreFunction · 0.85
mvccFromObjFunction · 0.85
dbOverwriteCoreMethod · 0.80
findMethod · 0.45
valMethod · 0.45

Tested by

no test coverage detected