Commit ef64333e authored by Wang Yuan's avatar Wang Yuan Committed by Oran Agra
Browse files

Expire key firstly and then notify keyspace event (#8830)

Modules event subscribers may get wrong things in notifyKeyspaceEvent callback,
such as wrong number of keys, or be able to lookup this key.
This commit changes the order to be like the one in evict.c.

Cleanup:
Since we know the key exists (it expires now), db*Delete is sure to return 1,
so there's no need to check it's output (misleading).

(cherry picked from commit 63acfe4b)
parent 08517053
...@@ -1541,14 +1541,17 @@ int expireIfNeeded(redisDb *db, robj *key) { ...@@ -1541,14 +1541,17 @@ int expireIfNeeded(redisDb *db, robj *key) {
if (checkClientPauseTimeoutAndReturnIfPaused()) return 1; if (checkClientPauseTimeoutAndReturnIfPaused()) return 1;
/* Delete the key */ /* Delete the key */
if (server.lazyfree_lazy_expire) {
dbAsyncDelete(db,key);
} else {
dbSyncDelete(db,key);
}
server.stat_expiredkeys++; server.stat_expiredkeys++;
propagateExpire(db,key,server.lazyfree_lazy_expire); propagateExpire(db,key,server.lazyfree_lazy_expire);
notifyKeyspaceEvent(NOTIFY_EXPIRED, notifyKeyspaceEvent(NOTIFY_EXPIRED,
"expired",key,db->id); "expired",key,db->id);
int retval = server.lazyfree_lazy_expire ? dbAsyncDelete(db,key) : signalModifiedKey(NULL,db,key);
dbSyncDelete(db,key); return 1;
if (retval) signalModifiedKey(NULL,db,key);
return retval;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment