]> git.saurik.com Git - redis.git/commitdiff
don't process EXPIRE with negative TTL or EXPIREAT with time in the past if we are...
authorantirez <antirez@gmail.com>
Thu, 7 Jul 2011 14:24:37 +0000 (16:24 +0200)
committerantirez <antirez@gmail.com>
Thu, 7 Jul 2011 14:24:37 +0000 (16:24 +0200)
src/db.c

index 47994df20eb7bcfb6fce90f890cbc163bfb401b3..26af2f21a4348f61328f8335e91c10508eaa7256 100644 (file)
--- a/src/db.c
+++ b/src/db.c
@@ -516,10 +516,24 @@ void expireGenericCommand(redisClient *c, robj *key, robj *param, long offset) {
         addReply(c,shared.czero);
         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);
         signalModifiedKey(c->db,key);
+        addReply(c, shared.cone);
         return;
     } else {
         time_t when = time(NULL)+seconds;