mirror of https://github.com/tidwall/tile38.git
Merge pull request #695 from Kilowhisky/fix/694
Fix ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in t…
This commit is contained in:
commit
f3c2cca898
|
@ -205,6 +205,25 @@ func (s *Server) liveSubscription(
|
||||||
write([]byte("+OK\r\n"))
|
write([]byte("+OK\r\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
writePing := func(m *Message) {
|
||||||
|
switch outputType {
|
||||||
|
case JSON:
|
||||||
|
if len(m.Args) > 1 {
|
||||||
|
write([]byte(`{"ok":true,"ping":` + jsonString(m.Args[1]) + `,"elapsed":"` + time.Since(start).String() + `"}`))
|
||||||
|
} else {
|
||||||
|
write([]byte(`{"ok":true,"ping":"pong","elapsed":"` + time.Since(start).String() + `"}`))
|
||||||
|
}
|
||||||
|
case RESP:
|
||||||
|
data := redcon.AppendArray(nil, 2)
|
||||||
|
data = redcon.AppendBulkString(data, "PONG")
|
||||||
|
if len(m.Args) > 1 {
|
||||||
|
data = redcon.AppendBulkString(data, m.Args[1])
|
||||||
|
} else {
|
||||||
|
data = redcon.AppendBulkString(data, "")
|
||||||
|
}
|
||||||
|
write(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
writeWrongNumberOfArgsErr := func(command string) {
|
writeWrongNumberOfArgsErr := func(command string) {
|
||||||
switch outputType {
|
switch outputType {
|
||||||
case JSON:
|
case JSON:
|
||||||
|
@ -335,6 +354,9 @@ func (s *Server) liveSubscription(
|
||||||
case "quit":
|
case "quit":
|
||||||
writeOK()
|
writeOK()
|
||||||
return nil
|
return nil
|
||||||
|
case "ping":
|
||||||
|
writePing(msg)
|
||||||
|
continue
|
||||||
case "psubscribe":
|
case "psubscribe":
|
||||||
kind, un = pubsubPattern, false
|
kind, un = pubsubPattern, false
|
||||||
case "punsubscribe":
|
case "punsubscribe":
|
||||||
|
|
Loading…
Reference in New Issue