summaryrefslogtreecommitdiff
path: root/src/db.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-09-14 12:28:22 +0200
committerantirez <antirez@gmail.com>2015-09-14 12:30:00 +0200
commitf529a01c1b52367b4337119ae8f86fd1d790a5ea (patch)
tree35378e1d704d66ae0d53fda5a21dc67cae9936db /src/db.c
parent33769f840cd53f03caf8f4b886a7c95182492027 (diff)
downloadredis-f529a01c1b52367b4337119ae8f86fd1d790a5ea.tar.gz
MOVE now can move TTL metadata as well.
MOVE was not able to move the TTL: when a key was moved into a different database number, it became persistent like if PERSIST was used. In some incredible way (I guess almost nobody uses Redis MOVE) this bug remained unnoticed inside Redis internals for many years. Finally Andy Grunwald discovered it and opened an issue. This commit fixes the bug and adds a regression test. Close #2765.
Diffstat (limited to 'src/db.c')
-rw-r--r--src/db.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/db.c b/src/db.c
index 1100c7ef7..df2e50ca5 100644
--- a/src/db.c
+++ b/src/db.c
@@ -743,7 +743,7 @@ void moveCommand(client *c) {
robj *o;
redisDb *src, *dst;
int srcid;
- long long dbid;
+ long long dbid, expire;
if (server.cluster_enabled) {
addReplyError(c,"MOVE is not allowed in cluster mode");
@@ -777,6 +777,7 @@ void moveCommand(client *c) {
addReply(c,shared.czero);
return;
}
+ expire = getExpire(c->db,c->argv[1]);
/* Return zero if the key already exists in the target DB */
if (lookupKeyWrite(dst,c->argv[1]) != NULL) {
@@ -784,6 +785,7 @@ void moveCommand(client *c) {
return;
}
dbAdd(dst,c->argv[1],o);
+ if (expire) setExpire(dst,c->argv[1],expire);
incrRefCount(o);
/* OK! key moved, free the entry in the source DB */