Skip to content

Commit

Permalink
Remove PMessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Apr 9, 2016
1 parent 1fbb109 commit d79074e
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 35 deletions.
1 change: 0 additions & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})

Expand All @@ -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)))
})
})
28 changes: 4 additions & 24 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d79074e

Please sign in to comment.