mirror of https://github.com/tidwall/tile38.git
add echo command (#201)
This commit is contained in:
parent
90f87bc3fb
commit
1ccaf71375
|
@ -409,16 +409,22 @@ func (c *Controller) handleInputCommand(conn *server.Conn, msg *server.Message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ping. Just send back the response. No need to put through the pipeline.
|
// Ping. Just send back the response. No need to put through the pipeline.
|
||||||
if msg.Command == "ping" {
|
if msg.Command == "ping" || msg.Command == "echo" {
|
||||||
switch msg.OutputType {
|
switch msg.OutputType {
|
||||||
case server.JSON:
|
case server.JSON:
|
||||||
return writeOutput(`{"ok":true,"ping":"pong","elapsed":"` + time.Now().Sub(start).String() + `"}`)
|
if len(msg.Values) > 1 {
|
||||||
|
return writeOutput(`{"ok":true,"` + msg.Command + `":` + jsonString(msg.Values[1].String()) + `,"elapsed":"` + time.Now().Sub(start).String() + `"}`)
|
||||||
|
}
|
||||||
|
return writeOutput(`{"ok":true,"` + msg.Command + `":"pong","elapsed":"` + time.Now().Sub(start).String() + `"}`)
|
||||||
case server.RESP:
|
case server.RESP:
|
||||||
|
if len(msg.Values) > 1 {
|
||||||
|
data, _ := msg.Values[1].MarshalRESP()
|
||||||
|
return writeOutput(string(data))
|
||||||
|
}
|
||||||
return writeOutput("+PONG\r\n")
|
return writeOutput("+PONG\r\n")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
writeErr := func(err error) error {
|
writeErr := func(err error) error {
|
||||||
switch msg.OutputType {
|
switch msg.OutputType {
|
||||||
case server.JSON:
|
case server.JSON:
|
||||||
|
@ -496,6 +502,7 @@ func (c *Controller) handleInputCommand(conn *server.Conn, msg *server.Message,
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
case "output":
|
case "output":
|
||||||
// this is local connection operation. Locks not needed.
|
// this is local connection operation. Locks not needed.
|
||||||
|
case "echo":
|
||||||
case "massinsert":
|
case "massinsert":
|
||||||
// dev operation
|
// dev operation
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
|
Loading…
Reference in New Issue