diff --git a/commands.go b/commands.go index a3b90f12..c04b3c49 100644 --- a/commands.go +++ b/commands.go @@ -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 } diff --git a/pubsub_test.go b/pubsub_test.go index 6fc04a19..6a85bd03 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -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))) + }) }) diff --git a/race_test.go b/race_test.go index 5bcb0768..14264086 100644 --- a/race_test.go +++ b/race_test.go @@ -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 +}