Skip to content

Commit

Permalink
Merge pull request redis#649 from go-redis/fix/receive-big-message
Browse files Browse the repository at this point in the history
Add test for receive big message payload
  • Loading branch information
vmihailenco authored Sep 30, 2017
2 parents 8e6b51e + 742a581 commit 9c20773
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type Cmdable interface {
ScriptKill() *StatusCmd
ScriptLoad(script string) *StringCmd
DebugObject(key string) *StringCmd
Publish(channel string, message interface{}) *IntCmd
PubSubChannels(pattern string) *StringSliceCmd
PubSubNumSub(channels ...string) *StringIntMapCmd
PubSubNumPat() *IntCmd
Expand Down Expand Up @@ -1880,8 +1881,8 @@ func (c *cmdable) DebugObject(key string) *StringCmd {
//------------------------------------------------------------------------------

// Publish posts the message to the channel.
func (c *cmdable) Publish(channel, message string) *IntCmd {
cmd := NewIntCmd("PUBLISH", channel, message)
func (c *cmdable) Publish(channel string, message interface{}) *IntCmd {
cmd := NewIntCmd("publish", channel, message)
c.process(cmd)
return cmd
}
Expand Down
16 changes: 16 additions & 0 deletions pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,20 @@ var _ = Describe("PubSub", func() {

wg.Wait()
})

It("handles big message payload", func() {
pubsub := client.Subscribe("mychannel")
defer pubsub.Close()

ch := pubsub.Channel()

bigVal := bigVal()
err := client.Publish("mychannel", bigVal).Err()
Expect(err).NotTo(HaveOccurred())

var msg *redis.Message
Eventually(ch).Should(Receive(&msg))
Expect(msg.Channel).To(Equal("mychannel"))
Expect(msg.Payload).To(Equal(string(bigVal)))
})
})
9 changes: 6 additions & 3 deletions race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var _ = Describe("races", func() {
It("should handle big vals in Get", func() {
C, N = 4, 100

bigVal := bytes.Repeat([]byte{'*'}, 1<<17) // 128kb
bigVal := bigVal()

err := client.Set("key", bigVal, 0).Err()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -126,8 +126,7 @@ var _ = Describe("races", func() {
It("should handle big vals in Set", func() {
C, N = 4, 100

bigVal := bytes.Repeat([]byte{'*'}, 1<<17) // 128kb

bigVal := bigVal()
perform(C, func(id int) {
for i := 0; i < N; i++ {
err := client.Set("key", bigVal, 0).Err()
Expand Down Expand Up @@ -245,3 +244,7 @@ var _ = Describe("races", func() {
Expect(n).To(Equal(int64(N)))
})
})

func bigVal() []byte {
return bytes.Repeat([]byte{'*'}, 1<<17) // 128kb
}

0 comments on commit 9c20773

Please sign in to comment.