Skip to content

Commit

Permalink
Merge PMessage and Message
Browse files Browse the repository at this point in the history
  • Loading branch information
garyburd committed Mar 14, 2018
1 parent 30da9cb commit 9c11da7
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions redis/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,9 @@ type Message struct {
// The originating channel.
Channel string

// The message data.
Data []byte
}

// PMessage represents a pmessage notification.
type PMessage struct {
// The matched pattern.
// The matched pattern, if any
Pattern string

// The originating channel.
Channel string

// The message data.
Data []byte
}
Expand Down Expand Up @@ -102,9 +93,9 @@ func (c PubSubConn) Ping(data string) error {
return c.Conn.Flush()
}

// Receive returns a pushed message as a Subscription, Message, PMessage, Pong
// or error. The return value is intended to be used directly in a type switch
// as illustrated in the PubSubConn example.
// Receive returns a pushed message as a Subscription, Message, Pong or error.
// The return value is intended to be used directly in a type switch as
// illustrated in the PubSubConn example.
func (c PubSubConn) Receive() interface{} {
return c.receiveInternal(c.Conn.Receive())
}
Expand Down Expand Up @@ -135,11 +126,11 @@ func (c PubSubConn) receiveInternal(replyArg interface{}, errArg error) interfac
}
return m
case "pmessage":
var pm PMessage
if _, err := Scan(reply, &pm.Pattern, &pm.Channel, &pm.Data); err != nil {
var m Message
if _, err := Scan(reply, &m.Pattern, &m.Channel, &m.Data); err != nil {
return err
}
return pm
return m
case "subscribe", "psubscribe", "unsubscribe", "punsubscribe":
s := Subscription{Kind: kind}
if _, err := Scan(reply, &s.Channel, &s.Count); err != nil {
Expand Down

0 comments on commit 9c11da7

Please sign in to comment.