1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Merge pull request #1448 from rueian/pubsub-message-payload-slice

Support string array in pubsub message payload
This commit is contained in:
Vladimir Mihailenco
2020-09-08 18:02:19 +03:00
committed by GitHub
2 changed files with 52 additions and 7 deletions

View File

@ -287,9 +287,10 @@ func (m *Subscription) String() string {
// Message received as result of a PUBLISH command issued by another client.
type Message struct {
Channel string
Pattern string
Payload string
Channel string
Pattern string
Payload string
PayloadSlice []string
}
func (m *Message) String() string {
@ -325,10 +326,24 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
Count: int(reply[2].(int64)),
}, nil
case "message":
return &Message{
Channel: reply[1].(string),
Payload: reply[2].(string),
}, nil
switch payload := reply[2].(type) {
case string:
return &Message{
Channel: reply[1].(string),
Payload: payload,
}, nil
case []interface{}:
ss := make([]string, len(payload))
for i, s := range payload {
ss[i] = s.(string)
}
return &Message{
Channel: reply[1].(string),
PayloadSlice: ss,
}, nil
default:
return nil, fmt.Errorf("redis: unsupported pubsub message payload: %T", payload)
}
case "pmessage":
return &Message{
Pattern: reply[1].(string),