Merge pull request #649 from go-redis/fix/receive-big-message

Add test for receive big message payload
This commit is contained in:
Vladimir Mihailenco 2017-09-30 09:27:44 +03:00 committed by GitHub
commit 9c20773cb2
3 changed files with 25 additions and 5 deletions

View File

@ -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
@ -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
}

View File

@ -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)))
})
})

View File

@ -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())
@ -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()
@ -245,3 +244,7 @@ var _ = Describe("races", func() {
Expect(n).To(Equal(int64(N)))
})
})
func bigVal() []byte {
return bytes.Repeat([]byte{'*'}, 1<<17) // 128kb
}