Remove PMessage.

This commit is contained in:
Vladimir Mihailenco 2016-04-09 11:45:56 +03:00
parent 1fbb1098f2
commit d79074eadb
7 changed files with 7 additions and 35 deletions

View File

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

View File

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

View File

@ -117,7 +117,6 @@ func newConnPool(opt *Options) *pool.ConnPool {
type PoolStats struct {
Requests uint32 // number of times a connection was requested by 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
TotalConns uint32 // the number of total connections in the pool

View File

@ -109,7 +109,6 @@ var _ = Describe("pool", func() {
stats := pool.Stats()
Expect(stats.Requests).To(Equal(uint32(4)))
Expect(stats.Hits).To(Equal(uint32(2)))
Expect(stats.Waits).To(Equal(uint32(0)))
Expect(stats.Timeouts).To(Equal(uint32(0)))
})
@ -127,7 +126,6 @@ var _ = Describe("pool", func() {
stats := pool.Stats()
Expect(stats.Requests).To(Equal(uint32(101)))
Expect(stats.Hits).To(Equal(uint32(100)))
Expect(stats.Waits).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)
}
// 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.
type Pong struct {
Payload string
@ -206,7 +192,7 @@ func (c *PubSub) newMessage(reply []interface{}) (interface{}, error) {
Payload: reply[2].(string),
}, nil
case "pmessage":
return &PMessage{
return &Message{
Pattern: reply[1].(string),
Channel: reply[2].(string),
Payload: reply[3].(string),
@ -244,9 +230,9 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
return c.newMessage(cmd.Val())
}
// Receive returns a message as a Subscription, Message, PMessage,
// Pong or error. See PubSub example for details. This is low-level
// API and most clients should use ReceiveMessage.
// Receive returns a message as a Subscription, Message, Pong or error.
// See PubSub example for details. This is low-level API and most clients
// should use ReceiveMessage.
func (c *PubSub) Receive() (interface{}, error) {
return c.ReceiveTimeout(0)
}
@ -290,12 +276,6 @@ func (c *PubSub) ReceiveMessage() (*Message, error) {
// Ignore.
case *Message:
return msg, nil
case *PMessage:
return &Message{
Channel: msg.Channel,
Pattern: msg.Pattern,
Payload: msg.Payload,
}, nil
default:
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)
Expect(err).NotTo(HaveOccurred())
subscr := msgi.(*redis.PMessage)
subscr := msgi.(*redis.Message)
Expect(subscr.Channel).To(Equal("mychannel1"))
Expect(subscr.Pattern).To(Equal("mychannel*"))
Expect(subscr.Payload).To(Equal("hello"))
@ -69,7 +69,7 @@ var _ = Describe("PubSub", func() {
}
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() {
@ -196,7 +196,7 @@ var _ = Describe("PubSub", func() {
}
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() {

View File

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