/* 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. */
void dbOverwrite(redisDb *db, robj *key, robj *val) {
dictEntry *de = dictFind(db->dict,key->ptr);
serverAssertWithInfo(NULL,key,de != NULL);
dictEntry auxentry = *de;
robj *old = dictGetVal(de);
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
val->lru = old->lru;
}
dictSetVal(db->dict, de, val);
if (server.lazyfree_lazy_server_del) {
/**
* 异步删除旧值
*/
freeObjAsync(old);
/**
* 将当前需要释放的旧值auxentry的值指针设置为NULL
* 这样做是为了避免下一步的dictFreeVal操作执行真实的释放操作
*/
dictSetVal(db->dict, &auxentry, NULL);
}
/**
* 执行释放操作
*/
dictFreeVal(db->dict, &auxentry);
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。