Skip to content

Commit

Permalink
Merge pull request redis#466 from go-redis/fix/client-instrumentation
Browse files Browse the repository at this point in the history
Fix Client process instrumentation.
  • Loading branch information
vmihailenco authored Dec 30, 2016
2 parents 57efac6 + 3eb7c87 commit 8fcba2e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 51 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
# Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.png?branch=v5)](https://travis-ci.org/go-redis/redis)

Supports:

- Redis 3 commands except QUIT, MONITOR, SLOWLOG and SYNC.
- [Pub/Sub](http://godoc.org/gopkg.in/redis.v5#PubSub).
- [Transactions](http://godoc.org/gopkg.in/redis.v5#Multi).
- [Pub/Sub](https://godoc.org/gopkg.in/redis.v5#PubSub).
- [Transactions](https://godoc.org/gopkg.in/redis.v5#Multi).
- [Pipeline](https://godoc.org/gopkg.in/redis.v5#example-Client-Pipeline) and [TxPipeline](https://godoc.org/gopkg.in/redis.v5#example-Client-TxPipeline).
- [Scripting](http://godoc.org/gopkg.in/redis.v5#Script).
- [Timeouts](http://godoc.org/gopkg.in/redis.v5#Options).
- [Redis Sentinel](http://godoc.org/gopkg.in/redis.v5#NewFailoverClient).
- [Redis Cluster](http://godoc.org/gopkg.in/redis.v5#NewClusterClient).
- [Ring](http://godoc.org/gopkg.in/redis.v5#NewRing).
- [Scripting](https://godoc.org/gopkg.in/redis.v5#Script).
- [Timeouts](https://godoc.org/gopkg.in/redis.v5#Options).
- [Redis Sentinel](https://godoc.org/gopkg.in/redis.v5#NewFailoverClient).
- [Redis Cluster](https://godoc.org/gopkg.in/redis.v5#NewClusterClient).
- [Ring](https://godoc.org/gopkg.in/redis.v5#NewRing).
- [Instrumentation](https://godoc.org/gopkg.in/redis.v5#ex-package--Instrumentation).
- [Cache friendly](https://github.com/go-redis/cache).
- [Rate limiting](https://github.com/go-redis/rate).
- [Distributed Locks](https://github.com/bsm/redis-lock).

API docs: http://godoc.org/gopkg.in/redis.v5.
Examples: http://godoc.org/gopkg.in/redis.v5#pkg-examples.
API docs: https://godoc.org/gopkg.in/redis.v5.
Examples: https://godoc.org/gopkg.in/redis.v5#pkg-examples.

## Installation

Expand Down Expand Up @@ -74,7 +75,7 @@ func ExampleClient() {

## Howto

Please go through [examples](http://godoc.org/gopkg.in/redis.v5#pkg-examples) to get an idea how to use this package.
Please go through [examples](https://godoc.org/gopkg.in/redis.v5#pkg-examples) to get an idea how to use this package.

## Look and feel

Expand Down
35 changes: 0 additions & 35 deletions example_instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"sync/atomic"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

redis "gopkg.in/redis.v5"
)

Expand Down Expand Up @@ -60,35 +57,3 @@ func wrapRedisProcess(client *redis.Client) {
}
})
}

var _ = Describe("Instrumentation", func() {
var client *redis.Client

BeforeEach(func() {
client = redis.NewClient(redisOptions())
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
})

AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})

Describe("WrapProcess", func() {

It("should call for client", func() {
wrapperFnCalled := false

client.WrapProcess(func(oldProcess func(redis.Cmder) error) func(redis.Cmder) error {
return func(cmd redis.Cmder) error {
wrapperFnCalled = true
return oldProcess(cmd)
}
})

client.Ping()

Expect(wrapperFnCalled).To(Equal(true))
})

})
})
12 changes: 7 additions & 5 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,14 @@ type Client struct {
}

func newClient(opt *Options, pool pool.Pooler) *Client {
base := baseClient{opt: opt, connPool: pool}
client := &Client{
baseClient: base,
cmdable: cmdable{base.Process},
client := Client{
baseClient: baseClient{
opt: opt,
connPool: pool,
},
}
return client
client.cmdable.process = client.Process
return &client
}

// NewClient returns a client to the Redis Server specified by Options.
Expand Down
15 changes: 15 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ var _ = Describe("Client", func() {
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(bigVal))
})

It("should call WrapProcess", func() {
var wrapperFnCalled bool

client.WrapProcess(func(oldProcess func(redis.Cmder) error) func(redis.Cmder) error {
return func(cmd redis.Cmder) error {
wrapperFnCalled = true
return oldProcess(cmd)
}
})

Expect(client.Ping().Err()).NotTo(HaveOccurred())

Expect(wrapperFnCalled).To(BeTrue())
})
})

var _ = Describe("Client timeout", func() {
Expand Down

0 comments on commit 8fcba2e

Please sign in to comment.