forked from mirror/redis
Merge pull request #47 from go-redis/fix/pub-sub-empty-pattern
Add optimization for '*' pattern in PubSubChannels.
This commit is contained in:
commit
0a00fb3a5d
|
@ -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