diff --git a/commands.go b/commands.go index 01e758a..99beb61 100644 --- a/commands.go +++ b/commands.go @@ -1212,7 +1212,11 @@ func (c *Client) DebugObject(key string) *StringCmd { //------------------------------------------------------------------------------ func (c *Client) PubSubChannels(pattern string) *StringSliceCmd { - cmd := NewStringSliceCmd("PUBSUB", "CHANNELS", pattern) + args := []string{"PUBSUB", "CHANNELS"} + if pattern != "*" { + args = append(args, pattern) + } + cmd := NewStringSliceCmd(args...) c.Process(cmd) return cmd } diff --git a/redis_test.go b/redis_test.go index 2407795..5aef878 100644 --- a/redis_test.go +++ b/redis_test.go @@ -2576,6 +2576,14 @@ func (t *RedisTest) TestPubSubChannels(c *C) { channels, err = t.client.PubSubChannels("mychannel*").Result() c.Assert(err, IsNil) c.Assert(sortStrings(channels), DeepEquals, []string{"mychannel", "mychannel2"}) + + channels, err = t.client.PubSubChannels("").Result() + c.Assert(err, IsNil) + c.Assert(channels, HasLen, 0) + + channels, err = t.client.PubSubChannels("*").Result() + c.Assert(err, IsNil) + c.Assert(len(channels) >= 2, Equals, true) } func (t *RedisTest) TestPubSubNumSub(c *C) {