Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
fc365a3a
Commit
fc365a3a
authored
Feb 23, 2015
by
antirez
Browse files
Change RENAME behavior when src and dst keys are the same.
Fixes issue #2392.
parent
0aa5acc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
fc365a3a
...
@@ -688,16 +688,20 @@ void shutdownCommand(redisClient *c) {
...
@@ -688,16 +688,20 @@ void shutdownCommand(redisClient *c) {
void
renameGenericCommand
(
redisClient
*
c
,
int
nx
)
{
void
renameGenericCommand
(
redisClient
*
c
,
int
nx
)
{
robj
*
o
;
robj
*
o
;
long
long
expire
;
long
long
expire
;
int
samekey
=
0
;
/* To use the same key as src and dst is probably an error */
/* When source and dest key is the same, no operation is performed,
if
(
sdscmp
(
c
->
argv
[
1
]
->
ptr
,
c
->
argv
[
2
]
->
ptr
)
==
0
)
{
* if the key exists, however we still return an error on unexisting key. */
addReply
(
c
,
shared
.
sameobjecterr
);
if
(
sdscmp
(
c
->
argv
[
1
]
->
ptr
,
c
->
argv
[
2
]
->
ptr
)
==
0
)
samekey
=
1
;
return
;
}
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nokeyerr
))
==
NULL
)
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nokeyerr
))
==
NULL
)
return
;
return
;
if
(
samekey
)
{
addReply
(
c
,
nx
?
shared
.
czero
:
shared
.
ok
);
return
;
}
incrRefCount
(
o
);
incrRefCount
(
o
);
expire
=
getExpire
(
c
->
db
,
c
->
argv
[
1
]);
expire
=
getExpire
(
c
->
db
,
c
->
argv
[
1
]);
if
(
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
])
!=
NULL
)
{
if
(
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
])
!=
NULL
)
{
...
...
tests/unit/basic.tcl
View file @
fc365a3a
...
@@ -368,7 +368,18 @@ start_server {tags {"basic"}} {
...
@@ -368,7 +368,18 @@ start_server {tags {"basic"}} {
format $err
format $err
}
{
ERR*
}
}
{
ERR*
}
test
{
RENAME where source and dest key is the same
}
{
test
{
RENAME where source and dest key are the same
(
existing
)}
{
r set mykey foo
r rename mykey mykey
}
{
OK
}
test
{
RENAMENX where source and dest key are the same
(
existing
)}
{
r set mykey foo
r renamenx mykey mykey
}
{
0
}
test
{
RENAME where source and dest key are the same
(
non existing
)}
{
r del mykey
catch
{
r rename mykey mykey
}
err
catch
{
r rename mykey mykey
}
err
format $err
format $err
}
{
ERR*
}
}
{
ERR*
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment