提交 4ab18a33 编写于 作者: A antirez

Fix for bug #128 about the RENAME command.

上级 02a3e582
...@@ -328,6 +328,7 @@ void shutdownCommand(redisClient *c) { ...@@ -328,6 +328,7 @@ void shutdownCommand(redisClient *c) {
void renameGenericCommand(redisClient *c, int nx) { void renameGenericCommand(redisClient *c, int nx) {
robj *o; robj *o;
time_t expire;
/* To use the same key as src and dst is probably an error */ /* To use the same key as src and dst is probably an error */
if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) { if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) {
...@@ -339,16 +340,18 @@ void renameGenericCommand(redisClient *c, int nx) { ...@@ -339,16 +340,18 @@ void renameGenericCommand(redisClient *c, int nx) {
return; return;
incrRefCount(o); incrRefCount(o);
expire = getExpire(c->db,c->argv[1]);
if (lookupKeyWrite(c->db,c->argv[2]) != NULL) { if (lookupKeyWrite(c->db,c->argv[2]) != NULL) {
if (nx) { if (nx) {
decrRefCount(o); decrRefCount(o);
addReply(c,shared.czero); addReply(c,shared.czero);
return; return;
} }
dbOverwrite(c->db,c->argv[2],o); /* Overwrite: delete the old key before creating the new one with the same name. */
} else { dbDelete(c->db,c->argv[2]);
dbAdd(c->db,c->argv[2],o);
} }
dbAdd(c->db,c->argv[2],o);
if (expire != -1) setExpire(c->db,c->argv[2],expire);
dbDelete(c->db,c->argv[1]); dbDelete(c->db,c->argv[1]);
signalModifiedKey(c->db,c->argv[1]); signalModifiedKey(c->db,c->argv[1]);
signalModifiedKey(c->db,c->argv[2]); signalModifiedKey(c->db,c->argv[2]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册