Skip to content

Commit

Permalink
Merge pull request #695 from Kilowhisky/fix/694
Browse files Browse the repository at this point in the history
Fix ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in t…
  • Loading branch information
tidwall authored Jul 31, 2023
2 parents a3f6669 + c45170d commit f3c2cca
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/server/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ func (s *Server) liveSubscription(
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) {
switch outputType {
case JSON:
Expand Down Expand Up @@ -335,6 +354,9 @@ func (s *Server) liveSubscription(
case "quit":
writeOK()
return nil
case "ping":
writePing(msg)
continue
case "psubscribe":
kind, un = pubsubPattern, false
case "punsubscribe":
Expand Down

0 comments on commit f3c2cca

Please sign in to comment.