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

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

上级 fa4c0aba
......@@ -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
......
......@@ -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},
......
......@@ -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},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册