]> git.saurik.com Git - redis.git/commitdiff
EXPIREAT implemented, will be useful for the append-only mode
authorantirez <antirez@gmail.com>
Thu, 29 Oct 2009 23:15:45 +0000 (00:15 +0100)
committerantirez <antirez@gmail.com>
Thu, 29 Oct 2009 23:15:45 +0000 (00:15 +0100)
TODO
redis-cli.c
redis.c

diff --git a/TODO b/TODO
index 941e667576d692e1aa6e711976d2a8e28b9f18a9..c464aa12ff5a26e6c56dc26d0b3a90ef26aa74d7 100644 (file)
--- 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
 
index cfd2081ac1a387781542d85d4cfaef7326943f05..aa99b6affb7720f12a036eac65a019518629f67d 100644 (file)
@@ -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 85df6d316a21d2f14bff435b686d09e78bf72a34..86a06af16a728ce3065a5475da6f4e2bd8f63260 100644 (file)
--- 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},