summaryrefslogtreecommitdiff
path: root/src/db.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-07-12 12:39:16 +0200
committerantirez <antirez@gmail.com>2011-07-12 12:39:16 +0200
commit0681c5ad844cefefbe62f30df6587c0cbec3272e (patch)
tree35ab1b7e8863dba2b728d2bae871042309206413 /src/db.c
parent15bc1cc1bcd4174e7116b5429f1f31f792d13d2e (diff)
parent34a8b51768a2579010e128b05e001bf1d8f99995 (diff)
downloadredis-0681c5ad844cefefbe62f30df6587c0cbec3272e.tar.gz
master branch merged into scripting.
Diffstat (limited to 'src/db.c')
-rw-r--r--src/db.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/db.c b/src/db.c
index a02f30438..26af2f21a 100644
--- a/src/db.c
+++ b/src/db.c
@@ -476,6 +476,9 @@ int expireIfNeeded(redisDb *db, robj *key) {
if (when < 0) return 0; /* No expire for this key */
+ /* Don't expire anything while loading. It will be done later. */
+ if (server.loading) return 0;
+
/* If we are running in the context of a slave, return ASAP:
* the slave key expiration is controlled by the master that will
* send us synthesized DEL operations for expired keys.
@@ -513,10 +516,24 @@ void expireGenericCommand(redisClient *c, robj *key, robj *param, long offset) {
addReply(c,shared.czero);
return;
}
- if (seconds <= 0) {
- 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;