From d79074eadb86ddedb17176798ba9331d7438d18c Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 9 Apr 2016 11:45:56 +0300 Subject: [PATCH] Remove PMessage. --- cluster.go | 1 - internal/pool/pool.go | 3 --- options.go | 1 - pool_test.go | 2 -- pubsub.go | 28 ++++------------------------ pubsub_test.go | 6 +++--- redis.go | 1 - 7 files changed, 7 insertions(+), 35 deletions(-) diff --git a/cluster.go b/cluster.go index baecb8f..12b1757 100644 --- a/cluster.go +++ b/cluster.go @@ -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 diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 700e660..302a2f8 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -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()) diff --git a/options.go b/options.go index 342e99d..6214496 100644 --- a/options.go +++ b/options.go @@ -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 diff --git a/pool_test.go b/pool_test.go index 942b9b9..bdf168a 100644 --- a/pool_test.go +++ b/pool_test.go @@ -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))) }) }) diff --git a/pubsub.go b/pubsub.go index 1bf2f93..844dfea 100644 --- a/pubsub.go +++ b/pubsub.go @@ -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) } diff --git a/pubsub_test.go b/pubsub_test.go index df0dd94..95ab153 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -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() { diff --git a/redis.go b/redis.go index ee4e69a..8899848 100644 --- a/redis.go +++ b/redis.go @@ -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,