diff --git a/src/db.c b/src/db.c index cb4c73710f69ac0983552d0d7c082f285a586ab8..1211af38b3fb5dae3e2bed5875d086fcc965d75e 100644 --- a/src/db.c +++ b/src/db.c @@ -496,9 +496,24 @@ void expireGenericCommand(redisClient *c, robj *key, robj *param, long offset) { return; } if (seconds <= 0 && !server.loading) { - if (dbDelete(c->db,key)) server.dirty++; - addReply(c, shared.cone); + /* EXPIRE with negative TTL, or EXPIREAT with a timestamp into the past + * should never be executed as a DEL when load the AOF or in the context + * of a slave instance. + * + * Instead we take the other branch of the IF statement setting an expire + * (possibly in the past) and wait for an explicit DEL from the master. */ + if (seconds <= 0 && !server.loading && !server.masterhost) { + robj *aux; + + redisAssert(dbDelete(c->db,key)); + server.dirty++; + + /* Replicate/AOF this as an explicit DEL. */ + aux = createStringObject("DEL",3); + rewriteClientCommandVector(c,2,aux,key); + decrRefCount(aux); touchWatchedKey(c->db,key); + addReply(c, shared.cone); return; } else { time_t when = time(NULL)+seconds;