From c438d40377eab513f1e44232f320d890c93f29f9 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 7 Oct 2014 15:40:00 +0300 Subject: [PATCH] Add optimization for '*' pattern in PubSubChannels. --- commands.go | 6 +++++- redis_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 01e758a7..99beb61f 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 2407795a..5aef878e 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) {