summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-07-07 16:24:37 +0200
committerantirez <antirez@gmail.com>2011-07-15 17:59:27 +0200
commitb8082ae7ba25f7e2da44223056f15a23374f8ca0 (patch)
tree59106d3593df878d8ad7403145909fa9d232f67f
parentd30dafe7f49c55e2cf51409986869c2b134c7672 (diff)
downloadredis-b8082ae7ba25f7e2da44223056f15a23374f8ca0.tar.gz
don't process EXPIRE with negative TTL or EXPIREAT with time in the past if we are a slave too (see http://groups.google.com/group/redis-db/browse_thread/thread/5a931fefb88b16d5). Also propagate it as DEL.
-rw-r--r--src/db.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/db.c b/src/db.c
index cb4c73710..1211af38b 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;