From c02609ad44f79f390e10a1db6972cd8fcf644780 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Sat, 7 Jan 2017 09:27:36 -0700 Subject: [PATCH] Fixed missing response in TTL json command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- controller/controller.go | 2 +- controller/crud.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 29f62fe2..f94ec04c 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -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": diff --git a/controller/crud.go b/controller/crud.go index eb525e76..aa1325b6 100644 --- a/controller/crud.go +++ b/controller/crud.go @@ -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 {