]> git.saurik.com Git - redis.git/blobdiff - src/db.c
FLUSHALL will only perform a blocking SAVE if RDB persistence is configured.
[redis.git] / src / db.c
index 7bfca543907377ded6467741391707903263a604..40b8148c3ab338537c7f871622edc8595c14e9c5 100644 (file)
--- a/src/db.c
+++ b/src/db.c
@@ -213,7 +213,7 @@ void flushallCommand(redisClient *c) {
         kill(server.bgsavechildpid,SIGKILL);
         rdbRemoveTempFile(server.bgsavechildpid);
     }
-    rdbSave(server.dbfilename);
+    if (server.saveparamslen > 0) rdbSave(server.dbfilename);
     server.dirty++;
 }
 
@@ -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]);