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. */
| 223 | * |
| 224 | * The program is aborted if the key was not already present. */ |
| 225 | void 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. |
no test coverage detected