diff --git a/controller/crud.go b/controller/crud.go index feaeef45..04facb2c 100644 --- a/controller/crud.go +++ b/controller/crud.go @@ -660,9 +660,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 @@ notok: switch msg.OutputType { default: 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" } diff --git a/controller/glob/glob.go b/controller/glob/glob.go index 696214a7..72eb9a7f 100644 --- a/controller/glob/glob.go +++ b/controller/glob/glob.go @@ -1,5 +1,7 @@ package glob +import "strings" + type Glob struct { Pattern string Desc bool @@ -24,7 +26,7 @@ func IsGlob(pattern string) bool { func Parse(pattern string, desc bool) *Glob { g := &Glob{Pattern: pattern, Desc: desc, Limits: []string{"", ""}} - if pattern == "*" { + if strings.HasPrefix(pattern, "*") { g.IsGlob = true return g } diff --git a/controller/token.go b/controller/token.go index 39cfa58a..5f0158dd 100644 --- a/controller/token.go +++ b/controller/token.go @@ -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) diff --git a/docker/README.md b/docker/README.md index 33487c89..11e1062b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,4 +1,4 @@ -![Tile38 Logo](https://github.com/tidwall/tile38/blob/master/doc/logo200.png) +![Tile38 Logo](https://raw.githubusercontent.com/tidwall/tile38/master/doc/logo200.png) Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types including lat/lon points, bounding boxes, XYZ tiles, Geohashes, and GeoJSON.