]> git.saurik.com Git - redis.git/commitdiff
PERSIST command implemented
authorantirez <antirez@gmail.com>
Tue, 3 Aug 2010 12:19:20 +0000 (14:19 +0200)
committerantirez <antirez@gmail.com>
Tue, 3 Aug 2010 12:19:20 +0000 (14:19 +0200)
src/db.c
src/redis.c
src/redis.h

index 5acda3d5ff065ad26738790d1a523ac2d68e9bc3..81e41430dcd3a399741cc5da6445ad8c933c54e3 100644 (file)
--- a/src/db.c
+++ b/src/db.c
@@ -394,11 +394,7 @@ int removeExpire(redisDb *db, robj *key) {
     /* An expire may only be removed if there is a corresponding entry in the
      * main dict. Otherwise, the key will never be freed. */
     redisAssert(dictFind(db->dict,key->ptr) != NULL);
-    if (dictDelete(db->expires,key->ptr) == DICT_OK) {
-        return 1;
-    } else {
-        return 0;
-    }
+    return dictDelete(db->expires,key->ptr) == DICT_OK;
 }
 
 void setExpire(redisDb *db, robj *key, time_t when) {
@@ -528,3 +524,17 @@ void ttlCommand(redisClient *c) {
     }
     addReplySds(c,sdscatprintf(sdsempty(),":%d\r\n",ttl));
 }
+
+void persistCommand(redisClient *c) {
+    dictEntry *de;
+
+    de = dictFind(c->db->dict,c->argv[1]->ptr);
+    if (de == NULL) {
+        addReply(c,shared.czero);
+    } else {
+        if (removeExpire(c->db,c->argv[1]))
+            addReply(c,shared.cone);
+        else
+            addReply(c,shared.czero);
+    }
+}
index 27ade8b19c2904f1837eb4a326f76c9cf7630797..1a581a92a2c607abb943820cf777506b988234c3 100644 (file)
@@ -170,6 +170,7 @@ struct redisCommand readonlyCommandTable[] = {
     {"info",infoCommand,1,REDIS_CMD_INLINE,NULL,0,0,0},
     {"monitor",monitorCommand,1,REDIS_CMD_INLINE,NULL,0,0,0},
     {"ttl",ttlCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
+    {"persist",persistCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
     {"slaveof",slaveofCommand,3,REDIS_CMD_INLINE,NULL,0,0,0},
     {"debug",debugCommand,-2,REDIS_CMD_INLINE,NULL,0,0,0},
     {"config",configCommand,-2,REDIS_CMD_BULK,NULL,0,0,0},
index c211cfb5e9d4bc9d2c20d2187d01a3862a7094f8..781fb209e2274328e3a3ff6b393e133f06144da1 100644 (file)
@@ -838,6 +838,7 @@ void expireCommand(redisClient *c);
 void expireatCommand(redisClient *c);
 void getsetCommand(redisClient *c);
 void ttlCommand(redisClient *c);
+void persistCommand(redisClient *c);
 void slaveofCommand(redisClient *c);
 void debugCommand(redisClient *c);
 void msetCommand(redisClient *c);