]> git.saurik.com Git - redis.git/commitdiff
Merge pull request #126 from florean/unstable
authorSalvatore Sanfilippo <antirez@gmail.com>
Mon, 10 Oct 2011 20:05:16 +0000 (13:05 -0700)
committerSalvatore Sanfilippo <antirez@gmail.com>
Mon, 10 Oct 2011 20:05:16 +0000 (13:05 -0700)
Unlink Unix socket file on shutdown

src/db.c
src/redis.c
tests/unit/basic.tcl

index 7bfca543907377ded6467741391707903263a604..9620b6e8f640f10cbecf6172642aadc2d9be2de2 100644 (file)
--- a/src/db.c
+++ b/src/db.c
@@ -328,6 +328,7 @@ void shutdownCommand(redisClient *c) {
 
 void renameGenericCommand(redisClient *c, int nx) {
     robj *o;
+    time_t expire;
 
     /* To use the same key as src and dst is probably an error */
     if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) {
@@ -339,16 +340,18 @@ void renameGenericCommand(redisClient *c, int nx) {
         return;
 
     incrRefCount(o);
+    expire = getExpire(c->db,c->argv[1]);
     if (lookupKeyWrite(c->db,c->argv[2]) != NULL) {
         if (nx) {
             decrRefCount(o);
             addReply(c,shared.czero);
             return;
         }
-        dbOverwrite(c->db,c->argv[2],o);
-    } else {
-        dbAdd(c->db,c->argv[2],o);
+        /* Overwrite: delete the old key before creating the new one with the same name. */
+        dbDelete(c->db,c->argv[2]);
     }
+    dbAdd(c->db,c->argv[2],o);
+    if (expire != -1) setExpire(c->db,c->argv[2],expire);
     dbDelete(c->db,c->argv[1]);
     signalModifiedKey(c->db,c->argv[1]);
     signalModifiedKey(c->db,c->argv[2]);
index 295936df1c964023944f2e87176a4c1cba26ae21..658d24867aa975d43810d911beade5db0a79aac3 100644 (file)
@@ -1515,10 +1515,10 @@ sds genRedisInfoString(char *section) {
         "used_cpu_user:%.2f\r\n"
         "used_cpu_sys_children:%.2f\r\n"
         "used_cpu_user_children:%.2f\r\n",
-        (float)self_ru.ru_utime.tv_sec+(float)self_ru.ru_utime.tv_usec/1000000,
         (float)self_ru.ru_stime.tv_sec+(float)self_ru.ru_stime.tv_usec/1000000,
-        (float)c_ru.ru_utime.tv_sec+(float)c_ru.ru_utime.tv_usec/1000000,
-        (float)c_ru.ru_stime.tv_sec+(float)c_ru.ru_stime.tv_usec/1000000);
+        (float)self_ru.ru_utime.tv_sec+(float)self_ru.ru_utime.tv_usec/1000000,
+        (float)c_ru.ru_stime.tv_sec+(float)c_ru.ru_stime.tv_usec/1000000,
+        (float)c_ru.ru_utime.tv_sec+(float)c_ru.ru_utime.tv_usec/1000000);
     }
 
     /* cmdtime */
index a7267fd8f43c577c266c5f9a78b2b83b1473cb91..86645e95fe308aa98051447ce32dfadb449597be 100644 (file)
@@ -262,6 +262,25 @@ start_server {tags {"basic"}} {
         format $err
     } {ERR*}
 
+    test {RENAME with volatile key, should move the TTL as well} {
+        r del mykey mykey2
+        r set mykey foo
+        r expire mykey 100
+        assert {[r ttl mykey] > 95 && [r ttl mykey] <= 100}
+        r rename mykey mykey2
+        assert {[r ttl mykey2] > 95 && [r ttl mykey2] <= 100}
+    }
+
+    test {RENAME with volatile key, should not inherit TTL of target key} {
+        r del mykey mykey2
+        r set mykey foo
+        r set mykey2 bar
+        r expire mykey2 100
+        assert {[r ttl mykey] == -1 && [r ttl mykey2] > 0}
+        r rename mykey mykey2
+        r ttl mykey2
+    } {-1}
+
     test {DEL all keys again (DB 0)} {
         foreach key [r keys *] {
             r del $key