1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Extract pipeline and multi/exec support to separate files.

This commit is contained in:
Vladimir Mihailenco
2012-08-11 17:42:10 +03:00
parent 83664bb3a8
commit 2f4156dd04
8 changed files with 1273 additions and 1021 deletions

View File

@ -6,19 +6,29 @@ import (
)
type PubSubClient struct {
*Client
*BaseClient
ch chan *Message
once sync.Once
}
func newPubSubClient(client *Client) (*PubSubClient, error) {
c := &PubSubClient{
Client: &Client{
ConnPool: NewSingleConnPool(client.ConnPool),
return &PubSubClient{
BaseClient: &BaseClient{
ConnPool: NewSingleConnPool(client.ConnPool, false),
InitConn: client.InitConn,
},
ch: make(chan *Message),
}
return c, nil
}, 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)
return req
}
type Message struct {
@ -28,12 +38,7 @@ type Message struct {
Err error
}
func (c *PubSubClient) consumeMessages() {
conn, err := c.conn()
// SignleConnPool never returns error.
if err != nil {
panic(err)
}
func (c *PubSubClient) consumeMessages(conn *Conn) {
req := NewMultiBulkReq()
for {
@ -89,7 +94,7 @@ func (c *PubSubClient) subscribe(cmd string, channels ...string) (chan *Message,
}
c.once.Do(func() {
go c.consumeMessages()
go c.consumeMessages(conn)
})
return c.ch, nil