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

Function dbOverwrite

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

Overwrite an existing key with a new value. Incrementing the reference * count of the new value is up to the caller. * This function does not modify the expire time of the existing key. * * The program is aborted if the key was not already present. */

Source from the content-addressed store, hash-verified

223 *
224 * The program is aborted if the key was not already present. */
225void dbOverwrite(redisDb *db, robj *key, robj *val) {
226 dictEntry *de = dictFind(db->dict,key->ptr);
227
228 serverAssertWithInfo(NULL,key,de != NULL);
229 dictEntry auxentry = *de;
230 robj *old = dictGetVal(de);
231 if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
232 val->lru = old->lru;
233 }
234 /* Although the key is not really deleted from the database, we regard
235 overwrite as two steps of unlink+add, so we still need to call the unlink
236 callback of the module. */
237 moduleNotifyKeyUnlink(key,old);
238 dictSetVal(db->dict, de, val);
239
240 if (server.lazyfree_lazy_server_del) {
241 freeObjAsync(key,old);
242 dictSetVal(db->dict, &auxentry, NULL);
243 }
244
245 dictFreeVal(db->dict, &auxentry);
246}
247
248/* High level Set operation. This function can be used in order to set
249 * a key, whatever it was existing or not, to a new object.

Callers 5

incrDecrCommandFunction · 0.85
incrbyfloatCommandFunction · 0.85
genericSetKeyFunction · 0.85
dbUnshareStringValueFunction · 0.85
spopWithCountCommandFunction · 0.85

Calls 3

moduleNotifyKeyUnlinkFunction · 0.85
freeObjAsyncFunction · 0.85
dictFindFunction · 0.70

Tested by

no test coverage detected