Add optimization for '*' pattern in PubSubChannels.

This commit is contained in:
Vladimir Mihailenco 2014-10-07 15:40:00 +03:00
parent 7b28e6f9d2
commit c438d40377
2 changed files with 13 additions and 1 deletions

View File

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

View File

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