From c45170d211099edfc9a999dcf13e86470cb82efd Mon Sep 17 00:00:00 2001 From: Chris Rice Date: Wed, 26 Jul 2023 11:47:11 -0700 Subject: [PATCH] Use the right MSG variable? --- internal/server/pubsub.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/server/pubsub.go b/internal/server/pubsub.go index 22c973e8..f6faa9a5 100644 --- a/internal/server/pubsub.go +++ b/internal/server/pubsub.go @@ -205,23 +205,23 @@ func (s *Server) liveSubscription( write([]byte("+OK\r\n")) } } - writePing := func() { + writePing := func(m *Message) { switch outputType { case JSON: - if len(msg.Args) > 1 { - write([]byte(`{"ok":true,"ping":` + jsonString(msg.Args[1]) + `,"elapsed":"` + time.Since(start).String() + `"}`)) + 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: - if len(msg.Args) > 1 { - data := redcon.AppendArray(nil, 2) - data = redcon.AppendBulkString(data, "PONG") - data = redcon.AppendBulkString(data, msg.Args[1]) - write(data) + data := redcon.AppendArray(nil, 2) + data = redcon.AppendBulkString(data, "PONG") + if len(m.Args) > 1 { + data = redcon.AppendBulkString(data, m.Args[1]) } else { - write([]byte("+PONG\r\n")) + data = redcon.AppendBulkString(data, "") } + write(data) } } writeWrongNumberOfArgsErr := func(command string) { @@ -355,7 +355,7 @@ func (s *Server) liveSubscription( writeOK() return nil case "ping": - writePing() + writePing(msg) continue case "psubscribe": kind, un = pubsubPattern, false