1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Review API.

This commit is contained in:
Vladimir Mihailenco
2012-08-17 21:36:48 +03:00
parent df1b8a3f5c
commit 11e1783560
10 changed files with 818 additions and 621 deletions

View File

@ -11,20 +11,16 @@ type PubSubClient struct {
once sync.Once
}
func newPubSubClient(client *Client) (*PubSubClient, error) {
func (c *Client) PubSubClient() (*PubSubClient, error) {
return &PubSubClient{
BaseClient: &BaseClient{
ConnPool: NewSingleConnPool(client.ConnPool, false),
InitConn: client.InitConn,
ConnPool: NewSingleConnPool(c.ConnPool, false),
InitConn: c.InitConn,
},
ch: make(chan *Message),
}, nil
}
func (c *Client) PubSubClient() (*PubSubClient, error) {
return newPubSubClient(c)
}
func (c *Client) Publish(channel, message string) *IntReq {
req := NewIntReq("PUBLISH", channel, message)
c.Process(req)
@ -39,7 +35,7 @@ type Message struct {
}
func (c *PubSubClient) consumeMessages(conn *Conn) {
req := NewMultiBulkReq()
req := NewIfaceSliceReq()
for {
for {
@ -82,7 +78,7 @@ func (c *PubSubClient) consumeMessages(conn *Conn) {
func (c *PubSubClient) subscribe(cmd string, channels ...string) (chan *Message, error) {
args := append([]string{cmd}, channels...)
req := NewMultiBulkReq(args...)
req := NewIfaceSliceReq(args...)
conn, err := c.conn()
if err != nil {
@ -110,7 +106,7 @@ func (c *PubSubClient) PSubscribe(patterns ...string) (chan *Message, error) {
func (c *PubSubClient) unsubscribe(cmd string, channels ...string) error {
args := append([]string{cmd}, channels...)
req := NewMultiBulkReq(args...)
req := NewIfaceSliceReq(args...)
conn, err := c.conn()
if err != nil {