mirror of https://github.com/go-redis/redis.git
Merge pull request #44 from go-redis/feature/add-pubsub-cmds
Add pubsub* commands.
This commit is contained in:
commit
7b28e6f9d2
22
commands.go
22
commands.go
|
@ -1208,3 +1208,25 @@ func (c *Client) DebugObject(key string) *StringCmd {
|
||||||
c.Process(cmd)
|
c.Process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func (c *Client) PubSubChannels(pattern string) *StringSliceCmd {
|
||||||
|
cmd := NewStringSliceCmd("PUBSUB", "CHANNELS", pattern)
|
||||||
|
c.Process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) PubSubNumSub(channels ...string) *StringSliceCmd {
|
||||||
|
args := []string{"PUBSUB", "NUMSUB"}
|
||||||
|
args = append(args, channels...)
|
||||||
|
cmd := NewStringSliceCmd(args...)
|
||||||
|
c.Process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) PubSubNumPat() *IntCmd {
|
||||||
|
cmd := NewIntCmd("PUBSUB", "NUMPAT")
|
||||||
|
c.Process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
|
@ -2562,6 +2562,52 @@ func (t *RedisTest) TestPubSub(c *C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *RedisTest) TestPubSubChannels(c *C) {
|
||||||
|
channels, err := t.client.PubSubChannels("mychannel*").Result()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(channels, HasLen, 0)
|
||||||
|
c.Assert(channels, Not(IsNil))
|
||||||
|
|
||||||
|
pubsub := t.client.PubSub()
|
||||||
|
defer pubsub.Close()
|
||||||
|
|
||||||
|
c.Assert(pubsub.Subscribe("mychannel", "mychannel2"), IsNil)
|
||||||
|
|
||||||
|
channels, err = t.client.PubSubChannels("mychannel*").Result()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(sortStrings(channels), DeepEquals, []string{"mychannel", "mychannel2"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *RedisTest) TestPubSubNumSub(c *C) {
|
||||||
|
pubsub := t.client.PubSub()
|
||||||
|
defer pubsub.Close()
|
||||||
|
|
||||||
|
c.Assert(pubsub.Subscribe("mychannel", "mychannel2"), IsNil)
|
||||||
|
|
||||||
|
channels, err := t.client.PubSubNumSub("mychannel", "mychannel2", "mychannel3").Result()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(
|
||||||
|
channels,
|
||||||
|
DeepEquals,
|
||||||
|
[]string{"mychannel", "1", "mychannel2", "1", "mychannel3", "0"},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *RedisTest) TestPubSubNumPat(c *C) {
|
||||||
|
num, err := t.client.PubSubNumPat().Result()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(num, Equals, int64(0))
|
||||||
|
|
||||||
|
pubsub := t.client.PubSub()
|
||||||
|
defer pubsub.Close()
|
||||||
|
|
||||||
|
c.Assert(pubsub.PSubscribe("mychannel*"), IsNil)
|
||||||
|
|
||||||
|
num, err = t.client.PubSubNumPat().Result()
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(num, Equals, int64(1))
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (t *RedisTest) TestPipeline(c *C) {
|
func (t *RedisTest) TestPipeline(c *C) {
|
||||||
|
|
Loading…
Reference in New Issue