mirror of https://github.com/go-redis/redis.git
Add optimization for '*' pattern in PubSubChannels.
This commit is contained in:
parent
7b28e6f9d2
commit
c438d40377
|
@ -1212,7 +1212,11 @@ func (c *Client) DebugObject(key string) *StringCmd {
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (c *Client) PubSubChannels(pattern string) *StringSliceCmd {
|
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)
|
c.Process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -2576,6 +2576,14 @@ func (t *RedisTest) TestPubSubChannels(c *C) {
|
||||||
channels, err = t.client.PubSubChannels("mychannel*").Result()
|
channels, err = t.client.PubSubChannels("mychannel*").Result()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(sortStrings(channels), DeepEquals, []string{"mychannel", "mychannel2"})
|
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) {
|
func (t *RedisTest) TestPubSubNumSub(c *C) {
|
||||||
|
|
Loading…
Reference in New Issue