Fix ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context #694

This commit is contained in:
Chris Rice 2023-07-06 15:13:07 -07:00
parent d7a766c6d0
commit ec47a58ba1
1 changed files with 20 additions and 0 deletions

View File

@ -205,6 +205,23 @@ func (s *Server) liveSubscription(
write([]byte("+OK\r\n"))
}
}
writePing := func() {
switch msg.OutputType {
case JSON:
if len(msg.Args) > 1 {
write([]byte(`{"ok":true,"ping":` + jsonString(msg.Args[1]) + `,"elapsed":"` + time.Since(start).String() + `"}`))
} else {
write([]byte(`{"ok":true,"ping":"pong","elapsed":"` + time.Since(start).String() + `"}`))
}
case RESP:
if len(msg.Args) > 1 {
data := redcon.AppendBulkString(nil, msg.Args[1])
write(data)
} else {
write([]byte("+PONG\r\n"))
}
}
}
writeWrongNumberOfArgsErr := func(command string) {
switch outputType {
case JSON:
@ -335,6 +352,9 @@ func (s *Server) liveSubscription(
case "quit":
writeOK()
return nil
case "ping":
writePing()
continue
case "psubscribe":
kind, un = pubsubPattern, false
case "punsubscribe":