Merge pull request #300 from go-redis/fix/rm-pmessage

Remove PMessage.
This commit is contained in:
Vladimir Mihailenco 2016-04-09 12:43:19 +03:00
commit 294973c76f
7 changed files with 7 additions and 35 deletions

View File

@ -76,7 +76,6 @@ func (c *ClusterClient) PoolStats() *PoolStats {
s := client.connPool.Stats() s := client.connPool.Stats()
acc.Requests += s.Requests acc.Requests += s.Requests
acc.Hits += s.Hits acc.Hits += s.Hits
acc.Waits += s.Waits
acc.Timeouts += s.Timeouts acc.Timeouts += s.Timeouts
acc.TotalConns += s.TotalConns acc.TotalConns += s.TotalConns
acc.FreeConns += s.FreeConns acc.FreeConns += s.FreeConns

View File

@ -28,11 +28,9 @@ var timers = sync.Pool{
} }
// PoolStats contains pool state information and accumulated stats. // PoolStats contains pool state information and accumulated stats.
// TODO: remove Waits
type PoolStats struct { type PoolStats struct {
Requests uint32 // number of times a connection was requested by the pool Requests uint32 // number of times a connection was requested by the pool
Hits uint32 // number of times free connection was found in the pool Hits uint32 // number of times free connection was found in the pool
Waits uint32 // number of times the pool had to wait for a connection
Timeouts uint32 // number of times a wait timeout occurred Timeouts uint32 // number of times a wait timeout occurred
TotalConns uint32 // the number of total connections in the pool TotalConns uint32 // the number of total connections in the pool
@ -261,7 +259,6 @@ func (p *ConnPool) Stats() *PoolStats {
stats := PoolStats{} stats := PoolStats{}
stats.Requests = atomic.LoadUint32(&p.stats.Requests) stats.Requests = atomic.LoadUint32(&p.stats.Requests)
stats.Hits = atomic.LoadUint32(&p.stats.Hits) stats.Hits = atomic.LoadUint32(&p.stats.Hits)
stats.Waits = atomic.LoadUint32(&p.stats.Waits)
stats.Timeouts = atomic.LoadUint32(&p.stats.Timeouts) stats.Timeouts = atomic.LoadUint32(&p.stats.Timeouts)
stats.TotalConns = uint32(p.Len()) stats.TotalConns = uint32(p.Len())
stats.FreeConns = uint32(p.FreeLen()) stats.FreeConns = uint32(p.FreeLen())

View File

@ -117,7 +117,6 @@ func newConnPool(opt *Options) *pool.ConnPool {
type PoolStats struct { type PoolStats struct {
Requests uint32 // number of times a connection was requested by the pool Requests uint32 // number of times a connection was requested by the pool
Hits uint32 // number of times free connection was found in the pool Hits uint32 // number of times free connection was found in the pool
Waits uint32 // number of times the pool had to wait for a connection
Timeouts uint32 // number of times a wait timeout occurred Timeouts uint32 // number of times a wait timeout occurred
TotalConns uint32 // the number of total connections in the pool TotalConns uint32 // the number of total connections in the pool

View File

@ -109,7 +109,6 @@ var _ = Describe("pool", func() {
stats := pool.Stats() stats := pool.Stats()
Expect(stats.Requests).To(Equal(uint32(4))) Expect(stats.Requests).To(Equal(uint32(4)))
Expect(stats.Hits).To(Equal(uint32(2))) Expect(stats.Hits).To(Equal(uint32(2)))
Expect(stats.Waits).To(Equal(uint32(0)))
Expect(stats.Timeouts).To(Equal(uint32(0))) Expect(stats.Timeouts).To(Equal(uint32(0)))
}) })
@ -127,7 +126,6 @@ var _ = Describe("pool", func() {
stats := pool.Stats() stats := pool.Stats()
Expect(stats.Requests).To(Equal(uint32(101))) Expect(stats.Requests).To(Equal(uint32(101)))
Expect(stats.Hits).To(Equal(uint32(100))) Expect(stats.Hits).To(Equal(uint32(100)))
Expect(stats.Waits).To(Equal(uint32(0)))
Expect(stats.Timeouts).To(Equal(uint32(0))) Expect(stats.Timeouts).To(Equal(uint32(0)))
}) })
}) })

View File

@ -166,20 +166,6 @@ func (m *Message) String() string {
return fmt.Sprintf("Message<%s: %s>", m.Channel, m.Payload) return fmt.Sprintf("Message<%s: %s>", m.Channel, m.Payload)
} }
// TODO: remove PMessage if favor of Message
// Message matching a pattern-matching subscription received as result
// of a PUBLISH command issued by another client.
type PMessage struct {
Channel string
Pattern string
Payload string
}
func (m *PMessage) String() string {
return fmt.Sprintf("PMessage<%s: %s>", m.Channel, m.Payload)
}
// Pong received as result of a PING command issued by another client. // Pong received as result of a PING command issued by another client.
type Pong struct { type Pong struct {
Payload string Payload string
@ -206,7 +192,7 @@ func (c *PubSub) newMessage(reply []interface{}) (interface{}, error) {
Payload: reply[2].(string), Payload: reply[2].(string),
}, nil }, nil
case "pmessage": case "pmessage":
return &PMessage{ return &Message{
Pattern: reply[1].(string), Pattern: reply[1].(string),
Channel: reply[2].(string), Channel: reply[2].(string),
Payload: reply[3].(string), Payload: reply[3].(string),
@ -244,9 +230,9 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
return c.newMessage(cmd.Val()) return c.newMessage(cmd.Val())
} }
// Receive returns a message as a Subscription, Message, PMessage, // Receive returns a message as a Subscription, Message, Pong or error.
// Pong or error. See PubSub example for details. This is low-level // See PubSub example for details. This is low-level API and most clients
// API and most clients should use ReceiveMessage. // should use ReceiveMessage.
func (c *PubSub) Receive() (interface{}, error) { func (c *PubSub) Receive() (interface{}, error) {
return c.ReceiveTimeout(0) return c.ReceiveTimeout(0)
} }
@ -290,12 +276,6 @@ func (c *PubSub) ReceiveMessage() (*Message, error) {
// Ignore. // Ignore.
case *Message: case *Message:
return msg, nil return msg, nil
case *PMessage:
return &Message{
Channel: msg.Channel,
Pattern: msg.Pattern,
Payload: msg.Payload,
}, nil
default: default:
return nil, fmt.Errorf("redis: unknown message: %T", msgi) return nil, fmt.Errorf("redis: unknown message: %T", msgi)
} }

View File

@ -53,7 +53,7 @@ var _ = Describe("PubSub", func() {
{ {
msgi, err := pubsub.ReceiveTimeout(time.Second) msgi, err := pubsub.ReceiveTimeout(time.Second)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
subscr := msgi.(*redis.PMessage) subscr := msgi.(*redis.Message)
Expect(subscr.Channel).To(Equal("mychannel1")) Expect(subscr.Channel).To(Equal("mychannel1"))
Expect(subscr.Pattern).To(Equal("mychannel*")) Expect(subscr.Pattern).To(Equal("mychannel*"))
Expect(subscr.Payload).To(Equal("hello")) Expect(subscr.Payload).To(Equal("hello"))
@ -69,7 +69,7 @@ var _ = Describe("PubSub", func() {
} }
stats := client.PoolStats() stats := client.PoolStats()
Expect(stats.Requests - stats.Hits - stats.Waits).To(Equal(uint32(2))) Expect(stats.Requests - stats.Hits).To(Equal(uint32(2)))
}) })
It("should pub/sub channels", func() { It("should pub/sub channels", func() {
@ -196,7 +196,7 @@ var _ = Describe("PubSub", func() {
} }
stats := client.PoolStats() stats := client.PoolStats()
Expect(stats.Requests - stats.Hits - stats.Waits).To(Equal(uint32(2))) Expect(stats.Requests - stats.Hits).To(Equal(uint32(2)))
}) })
It("should ping/pong", func() { It("should ping/pong", func() {

View File

@ -167,7 +167,6 @@ func (c *Client) PoolStats() *PoolStats {
return &PoolStats{ return &PoolStats{
Requests: s.Requests, Requests: s.Requests,
Hits: s.Hits, Hits: s.Hits,
Waits: s.Waits,
Timeouts: s.Timeouts, Timeouts: s.Timeouts,
TotalConns: s.TotalConns, TotalConns: s.TotalConns,