mirror of https://github.com/tidwall/tile38.git
type command
This commit is contained in:
parent
04e5912107
commit
adef76af22
|
@ -363,7 +363,7 @@ func (c *Controller) handleInputCommand(conn *server.Conn, msg *server.Message,
|
|||
if c.config.ReadOnly {
|
||||
return writeErr(errors.New("read only"))
|
||||
}
|
||||
case "get", "keys", "scan", "nearby", "within", "intersects", "hooks", "search", "ttl", "bounds", "server", "info":
|
||||
case "get", "keys", "scan", "nearby", "within", "intersects", "hooks", "search", "ttl", "bounds", "server", "info", "type":
|
||||
// read operations
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
@ -480,6 +480,8 @@ func (c *Controller) command(msg *server.Message, w io.Writer) (res string, d co
|
|||
res, err = c.cmdBounds(msg)
|
||||
case "get":
|
||||
res, err = c.cmdGet(msg)
|
||||
case "type":
|
||||
res, err = c.cmdType(msg)
|
||||
case "keys":
|
||||
res, err = c.cmdKeys(msg)
|
||||
case "output":
|
||||
|
|
|
@ -104,6 +104,34 @@ func (c *Controller) cmdBounds(msg *server.Message) (string, error) {
|
|||
}
|
||||
return "", nil
|
||||
}
|
||||
func (c *Controller) cmdType(msg *server.Message) (string, error) {
|
||||
start := time.Now()
|
||||
vs := msg.Values[1:]
|
||||
|
||||
var ok bool
|
||||
var key string
|
||||
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
||||
return "", errInvalidNumberOfArguments
|
||||
}
|
||||
|
||||
col := c.getCol(key)
|
||||
if col == nil {
|
||||
if msg.OutputType == server.RESP {
|
||||
return "+none\r\n", nil
|
||||
}
|
||||
return "", errKeyNotFound
|
||||
}
|
||||
|
||||
typ := "hash"
|
||||
|
||||
switch msg.OutputType {
|
||||
case server.JSON:
|
||||
return `{"ok":true,"type":` + string(typ) + `,"elapsed":"` + time.Now().Sub(start).String() + "\"}", nil
|
||||
case server.RESP:
|
||||
return "+" + typ + "\r\n", nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *Controller) cmdGet(msg *server.Message) (string, error) {
|
||||
start := time.Now()
|
||||
|
|
|
@ -128,10 +128,11 @@ func (c *Controller) cmdServer(msg *server.Message) (res string, err error) {
|
|||
}
|
||||
res = string(data)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Controller) writeInfoServer(w *bytes.Buffer) {
|
||||
fmt.Fprintf(w, "tile38_version:%s\r\n", core.Version)
|
||||
fmt.Fprintf(w, "redis_version:%s\r\n", core.Version) //Version of the Redis server
|
||||
fmt.Fprintf(w, "uptime_in_seconds:%d\r\n", time.Now().Sub(c.started)/time.Second) //Number of seconds since Redis server start
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ func (c *Controller) cmdInfo(msg *server.Message) (res string, err error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
res = `{"ok":true,"stats":` + string(data) + `,"elapsed":"` + time.Now().Sub(start).String() + "\"}"
|
||||
res = `{"ok":true,"info":` + string(data) + `,"elapsed":"` + time.Now().Sub(start).String() + "\"}"
|
||||
case server.RESP:
|
||||
data, err := resp.StringValue(w.String()).MarshalRESP()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue