mirror of https://github.com/tidwall/tile38.git
Refactor to be more consistent with redis responses.
This commit is contained in:
parent
01a7dda2a1
commit
e1c82e17f7
|
@ -470,26 +470,27 @@ func (server *Server) cmdRename(msg *Message, nx bool) (res resp.Value, d comman
|
|||
err = errInvalidNumberOfArguments
|
||||
return
|
||||
}
|
||||
col := server.getCol(d.key)
|
||||
if col == nil {
|
||||
err = errKeyNotFound
|
||||
return
|
||||
}
|
||||
for _, h := range server.hooks {
|
||||
if h.Key == d.key || h.Key == d.newKey {
|
||||
err = errKeyHasHooksSet
|
||||
return
|
||||
}
|
||||
}
|
||||
col := server.getCol(d.key)
|
||||
if col == nil {
|
||||
err = errKeyNotFound
|
||||
return
|
||||
}
|
||||
d.command = "rename"
|
||||
d.updated = true
|
||||
newCol := server.getCol(d.newKey)
|
||||
if newCol != nil {
|
||||
if nx {
|
||||
if newCol == nil {
|
||||
d.updated = true
|
||||
} else if nx {
|
||||
d.updated = false
|
||||
} else {
|
||||
server.deleteCol(d.newKey)
|
||||
}
|
||||
server.clearKeyExpires(d.newKey)
|
||||
d.updated = true
|
||||
}
|
||||
if d.updated {
|
||||
server.deleteCol(d.key)
|
||||
|
@ -501,7 +502,9 @@ func (server *Server) cmdRename(msg *Message, nx bool) (res resp.Value, d comman
|
|||
case JSON:
|
||||
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Now().Sub(start).String() + "\"}")
|
||||
case RESP:
|
||||
if d.updated {
|
||||
if !nx {
|
||||
res = resp.SimpleStringValue("OK")
|
||||
} else if d.updated {
|
||||
res = resp.IntegerValue(1)
|
||||
} else {
|
||||
res = resp.IntegerValue(0)
|
||||
|
|
|
@ -72,11 +72,11 @@ func keys_RENAME_test(mc *mockServer) error {
|
|||
{"SET", "mykey", "myid1", "HASH", "9my5xp7"}, {"OK"},
|
||||
{"SET", "mykey", "myid2", "HASH", "9my5xp8"}, {"OK"},
|
||||
{"SCAN", "mykey", "COUNT"}, {2},
|
||||
{"RENAME", "mykey", "mynewkey"}, {1},
|
||||
{"RENAME", "mykey", "mynewkey"}, {"OK"},
|
||||
{"SCAN", "mykey", "COUNT"}, {0},
|
||||
{"SCAN", "mynewkey", "COUNT"}, {2},
|
||||
{"SET", "mykey", "myid3", "HASH", "9my5xp7"}, {"OK"},
|
||||
{"RENAME", "mykey", "mynewkey"}, {1},
|
||||
{"RENAME", "mykey", "mynewkey"}, {"OK"},
|
||||
{"SCAN", "mykey", "COUNT"}, {0},
|
||||
{"SCAN", "mynewkey", "COUNT"}, {1},
|
||||
{"RENAME", "foo", "mynewkey"}, {"ERR key not found"},
|
||||
|
|
Loading…
Reference in New Issue