Fixed missing response in TTL json command

Using the tile38-cli, the TTL command omitted the ttl value from the
json response.

For example:

    127.0.0.1:9851> TTL my ufo
    {"ok":true,"elapsed":"5.57µs"}

Is now fixed to show
    127.0.0.1:9851> TTL my ufo
    {"ok":true,"ttl":-1,"elapsed":"5.57µs"}

Where "ttl" is the remaining time before the object is is deleted.
The value -1 means that the object is available, but does not have
an expiration.

Thanks @phulst for finding this bug. closes #116
This commit is contained in:
Josh Baker 2017-01-07 09:27:36 -07:00
parent d3164f8bb9
commit c02609ad44
2 changed files with 13 additions and 3 deletions

View File

@ -503,7 +503,7 @@ func (c *Controller) command(msg *server.Message, w io.Writer) (res string, d co
case "persist":
res, d, err = c.cmdPersist(msg)
case "ttl":
res, d, err = c.cmdTTL(msg)
res, err = c.cmdTTL(msg)
case "hooks":
res, err = c.cmdHooks(msg)
case "shutdown":

View File

@ -940,7 +940,7 @@ func (c *Controller) cmdPersist(msg *server.Message) (res string, d commandDetai
return
}
func (c *Controller) cmdTTL(msg *server.Message) (res string, d commandDetailsT, err error) {
func (c *Controller) cmdTTL(msg *server.Message) (res string, err error) {
start := time.Now()
vs := msg.Values[1:]
var key, id string
@ -976,7 +976,17 @@ func (c *Controller) cmdTTL(msg *server.Message) (res string, d commandDetailsT,
}
switch msg.OutputType {
case server.JSON:
res = `{"ok":true,"elapsed":"` + time.Now().Sub(start).String() + "\"}"
if ok {
var ttl string
if ok2 {
ttl = strconv.FormatFloat(v, 'f', -1, 64)
} else {
ttl = "-1"
}
res = `{"ok":true,"ttl":` + ttl + `,"elapsed":"` + time.Now().Sub(start).String() + "\"}"
} else {
return "", errIDNotFound
}
case server.RESP:
if ok {
if ok2 {