mirror of https://github.com/tidwall/tile38.git
fix #77 NX/XX bug
This commit is contained in:
parent
0df21b998a
commit
fbff0f4eef
|
@ -662,9 +662,9 @@ func (c *Controller) cmdSet(msg *server.Message) (res string, d commandDetailsT,
|
|||
col = collection.New()
|
||||
c.setCol(d.key, col)
|
||||
}
|
||||
if nx {
|
||||
if xx || nx {
|
||||
_, _, ok := col.Get(d.id)
|
||||
if ok {
|
||||
if (nx && ok) || (xx && !ok) {
|
||||
goto notok
|
||||
}
|
||||
}
|
||||
|
@ -691,7 +691,12 @@ func (c *Controller) cmdSet(msg *server.Message) (res string, d commandDetailsT,
|
|||
notok:
|
||||
switch msg.OutputType {
|
||||
case server.JSON:
|
||||
res = `{"ok":false,"elapsed":"` + time.Now().Sub(start).String() + "\"}"
|
||||
if nx {
|
||||
err = errIDAlreadyExists
|
||||
} else {
|
||||
err = errIDNotFound
|
||||
}
|
||||
return
|
||||
case server.RESP:
|
||||
res = "$-1\r\n"
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ const defaultSearchOutput = outputObjects
|
|||
var errInvalidNumberOfArguments = errors.New("invalid number of arguments")
|
||||
var errKeyNotFound = errors.New("key not found")
|
||||
var errIDNotFound = errors.New("id not found")
|
||||
var errIDAlreadyExists = errors.New("id already exists")
|
||||
|
||||
func errInvalidArgument(arg string) error {
|
||||
return fmt.Errorf("invalid argument '%s'", arg)
|
||||
|
|
Loading…
Reference in New Issue