From 802e8373735c2708029f03b4b46ecc0e0ee50a1d Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 30 Oct 2009 00:15:45 +0100 Subject: [PATCH] EXPIREAT implemented, will be useful for the append-only mode --- TODO | 1 + redis-cli.c | 1 + redis.c | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 941e6675..c464aa12 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,7 @@ VERSION 1.1 TODO * Add all the missing symbols for the statis functions into the table. This backtrace on segfault is indeed *very* useful. * Use strcoll() to compare objects in sorted sets, like it already happens for SORT. * LMOVE, as discussed in the Redis group. +* EXPIRE and EXPIREAT tests. VERSION 1.2 TODO diff --git a/redis-cli.c b/redis-cli.c index cfd2081a..aa99b6af 100644 --- a/redis-cli.c +++ b/redis-cli.c @@ -120,6 +120,7 @@ static struct redisCommand cmdTable[] = { {"info",1,REDIS_CMD_INLINE}, {"mget",-2,REDIS_CMD_INLINE}, {"expire",3,REDIS_CMD_INLINE}, + {"expireat",3,REDIS_CMD_INLINE}, {"ttl",2,REDIS_CMD_INLINE}, {"slaveof",3,REDIS_CMD_INLINE}, {"debug",-2,REDIS_CMD_INLINE}, diff --git a/redis.c b/redis.c index 85df6d31..86a06af1 100644 --- a/redis.c +++ b/redis.c @@ -440,6 +440,7 @@ static void infoCommand(redisClient *c); static void mgetCommand(redisClient *c); static void monitorCommand(redisClient *c); static void expireCommand(redisClient *c); +static void expireatCommand(redisClient *c); static void getsetCommand(redisClient *c); static void ttlCommand(redisClient *c); static void slaveofCommand(redisClient *c); @@ -511,6 +512,7 @@ static struct redisCommand cmdTable[] = { {"rename",renameCommand,3,REDIS_CMD_INLINE}, {"renamenx",renamenxCommand,3,REDIS_CMD_INLINE}, {"expire",expireCommand,3,REDIS_CMD_INLINE}, + {"expireat",expireatCommand,3,REDIS_CMD_INLINE}, {"keys",keysCommand,2,REDIS_CMD_INLINE}, {"dbsize",dbsizeCommand,1,REDIS_CMD_INLINE}, {"auth",authCommand,2,REDIS_CMD_INLINE}, @@ -4736,11 +4738,10 @@ static int deleteIfVolatile(redisDb *db, robj *key) { return dictDelete(db->dict,key) == DICT_OK; } -static void expireCommand(redisClient *c) { +static void expireGenericCommand(redisClient *c, robj *key, time_t seconds) { dictEntry *de; - int seconds = atoi(c->argv[2]->ptr); - de = dictFind(c->db->dict,c->argv[1]); + de = dictFind(c->db->dict,key); if (de == NULL) { addReply(c,shared.czero); return; @@ -4750,7 +4751,7 @@ static void expireCommand(redisClient *c) { return; } else { time_t when = time(NULL)+seconds; - if (setExpire(c->db,c->argv[1],when)) { + if (setExpire(c->db,key,when)) { addReply(c,shared.cone); server.dirty++; } else { @@ -4760,6 +4761,14 @@ static void expireCommand(redisClient *c) { } } +static void expireCommand(redisClient *c) { + expireGenericCommand(c,c->argv[1],strtol(c->argv[2]->ptr,NULL,10)); +} + +static void expireatCommand(redisClient *c) { + expireGenericCommand(c,c->argv[1],strtol(c->argv[2]->ptr,NULL,10)-time(NULL)); +} + static void ttlCommand(redisClient *c) { time_t expire; int ttl = -1; @@ -5312,6 +5321,7 @@ static struct redisFunctionSym symsTable[] = { {"mgetCommand", (unsigned long)mgetCommand}, {"monitorCommand", (unsigned long)monitorCommand}, {"expireCommand", (unsigned long)expireCommand}, +{"expireatCommand", (unsigned long)expireatCommand}, {"getsetCommand", (unsigned long)getsetCommand}, {"ttlCommand", (unsigned long)ttlCommand}, {"slaveofCommand", (unsigned long)slaveofCommand}, -- GitLab