提交 802e8373 编写于 作者: A antirez

EXPIREAT implemented, will be useful for the append-only mode

上级 fa4c0aba
...@@ -6,6 +6,7 @@ VERSION 1.1 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. * 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. * Use strcoll() to compare objects in sorted sets, like it already happens for SORT.
* LMOVE, as discussed in the Redis group. * LMOVE, as discussed in the Redis group.
* EXPIRE and EXPIREAT tests.
VERSION 1.2 TODO VERSION 1.2 TODO
......
...@@ -120,6 +120,7 @@ static struct redisCommand cmdTable[] = { ...@@ -120,6 +120,7 @@ static struct redisCommand cmdTable[] = {
{"info",1,REDIS_CMD_INLINE}, {"info",1,REDIS_CMD_INLINE},
{"mget",-2,REDIS_CMD_INLINE}, {"mget",-2,REDIS_CMD_INLINE},
{"expire",3,REDIS_CMD_INLINE}, {"expire",3,REDIS_CMD_INLINE},
{"expireat",3,REDIS_CMD_INLINE},
{"ttl",2,REDIS_CMD_INLINE}, {"ttl",2,REDIS_CMD_INLINE},
{"slaveof",3,REDIS_CMD_INLINE}, {"slaveof",3,REDIS_CMD_INLINE},
{"debug",-2,REDIS_CMD_INLINE}, {"debug",-2,REDIS_CMD_INLINE},
......
...@@ -440,6 +440,7 @@ static void infoCommand(redisClient *c); ...@@ -440,6 +440,7 @@ static void infoCommand(redisClient *c);
static void mgetCommand(redisClient *c); static void mgetCommand(redisClient *c);
static void monitorCommand(redisClient *c); static void monitorCommand(redisClient *c);
static void expireCommand(redisClient *c); static void expireCommand(redisClient *c);
static void expireatCommand(redisClient *c);
static void getsetCommand(redisClient *c); static void getsetCommand(redisClient *c);
static void ttlCommand(redisClient *c); static void ttlCommand(redisClient *c);
static void slaveofCommand(redisClient *c); static void slaveofCommand(redisClient *c);
...@@ -511,6 +512,7 @@ static struct redisCommand cmdTable[] = { ...@@ -511,6 +512,7 @@ static struct redisCommand cmdTable[] = {
{"rename",renameCommand,3,REDIS_CMD_INLINE}, {"rename",renameCommand,3,REDIS_CMD_INLINE},
{"renamenx",renamenxCommand,3,REDIS_CMD_INLINE}, {"renamenx",renamenxCommand,3,REDIS_CMD_INLINE},
{"expire",expireCommand,3,REDIS_CMD_INLINE}, {"expire",expireCommand,3,REDIS_CMD_INLINE},
{"expireat",expireatCommand,3,REDIS_CMD_INLINE},
{"keys",keysCommand,2,REDIS_CMD_INLINE}, {"keys",keysCommand,2,REDIS_CMD_INLINE},
{"dbsize",dbsizeCommand,1,REDIS_CMD_INLINE}, {"dbsize",dbsizeCommand,1,REDIS_CMD_INLINE},
{"auth",authCommand,2,REDIS_CMD_INLINE}, {"auth",authCommand,2,REDIS_CMD_INLINE},
...@@ -4736,11 +4738,10 @@ static int deleteIfVolatile(redisDb *db, robj *key) { ...@@ -4736,11 +4738,10 @@ static int deleteIfVolatile(redisDb *db, robj *key) {
return dictDelete(db->dict,key) == DICT_OK; return dictDelete(db->dict,key) == DICT_OK;
} }
static void expireCommand(redisClient *c) { static void expireGenericCommand(redisClient *c, robj *key, time_t seconds) {
dictEntry *de; 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) { if (de == NULL) {
addReply(c,shared.czero); addReply(c,shared.czero);
return; return;
...@@ -4750,7 +4751,7 @@ static void expireCommand(redisClient *c) { ...@@ -4750,7 +4751,7 @@ static void expireCommand(redisClient *c) {
return; return;
} else { } else {
time_t when = time(NULL)+seconds; time_t when = time(NULL)+seconds;
if (setExpire(c->db,c->argv[1],when)) { if (setExpire(c->db,key,when)) {
addReply(c,shared.cone); addReply(c,shared.cone);
server.dirty++; server.dirty++;
} else { } else {
...@@ -4760,6 +4761,14 @@ static void expireCommand(redisClient *c) { ...@@ -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) { static void ttlCommand(redisClient *c) {
time_t expire; time_t expire;
int ttl = -1; int ttl = -1;
...@@ -5312,6 +5321,7 @@ static struct redisFunctionSym symsTable[] = { ...@@ -5312,6 +5321,7 @@ static struct redisFunctionSym symsTable[] = {
{"mgetCommand", (unsigned long)mgetCommand}, {"mgetCommand", (unsigned long)mgetCommand},
{"monitorCommand", (unsigned long)monitorCommand}, {"monitorCommand", (unsigned long)monitorCommand},
{"expireCommand", (unsigned long)expireCommand}, {"expireCommand", (unsigned long)expireCommand},
{"expireatCommand", (unsigned long)expireatCommand},
{"getsetCommand", (unsigned long)getsetCommand}, {"getsetCommand", (unsigned long)getsetCommand},
{"ttlCommand", (unsigned long)ttlCommand}, {"ttlCommand", (unsigned long)ttlCommand},
{"slaveofCommand", (unsigned long)slaveofCommand}, {"slaveofCommand", (unsigned long)slaveofCommand},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册