Skip to content

Commit

Permalink
don't process EXPIRE with negative TTL or EXPIREAT with time in the p…
Browse files Browse the repository at this point in the history
…ast if we are a slave too (see http://groups.google.com/group/redis-db/browse_thread/thread/5a931fefb88b16d5). Also propagate it as DEL.
  • Loading branch information
antirez committed Jul 12, 2011
1 parent 1945355 commit 64cb157
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,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;
Expand Down

0 comments on commit 64cb157

Please sign in to comment.