Add instrumentation example.

This commit is contained in:
Vladimir Mihailenco 2016-11-26 10:33:06 +02:00
parent f8ad82370f
commit d4a3b1f282
4 changed files with 25 additions and 25 deletions

View File

@ -32,22 +32,6 @@ Import:
import "gopkg.in/redis.v5"
```
## Vendoring
If you are using a vendoring tool with support for semantic versioning
e.g. [glide](https://github.com/Masterminds/glide), you can import this
package via its GitHub URL:
```yaml
- package: github.com/go-redis/redis
version: ^5.0.0
```
WARNING: please note that by importing `github.com/go-redis/redis`
directly (without semantic versioning constrol) you are in danger of
running in the breaking API changes. Use carefully and at your own
risk!
## Quickstart
```go

View File

@ -331,3 +331,21 @@ func ExampleScanCmd_Iterator() {
panic(err)
}
}
func ExampleClient_instrumentation() {
client := redis.NewClient(&redis.Options{
Addr: ":6379",
})
client.WrapProcess(func(oldProcess func(cmd redis.Cmder) error) func(cmd redis.Cmder) error {
return func(cmd redis.Cmder) error {
start := time.Now()
err := oldProcess(cmd)
if err != nil {
fmt.Printf("command %s failed: %s", cmd, err)
} else {
fmt.Printf("command %q took %s", cmd, time.Since(start))
}
return err
}
})
}

View File

@ -8,8 +8,8 @@ import (
"gopkg.in/redis.v5/internal"
)
func Scan(s string, val interface{}) error {
switch v := val.(type) {
func Scan(s string, v interface{}) error {
switch v := v.(type) {
case nil:
return internal.RedisError("redis: Scan(nil)")
case *string:
@ -99,12 +99,10 @@ func Scan(s string, val interface{}) error {
case *bool:
*v = len(s) == 1 && s[0] == '1'
return nil
case encoding.BinaryUnmarshaler:
return v.UnmarshalBinary([]byte(s))
default:
if bu, ok := val.(encoding.BinaryUnmarshaler); ok {
return bu.UnmarshalBinary([]byte(s))
}
err := fmt.Errorf(
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", val)
return err
return fmt.Errorf(
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)
}
}

View File

@ -1,4 +1,4 @@
package redis
package redis // import "gopkg.in/redis.v5"
import (
"fmt"