forked from mirror/redis
Add instrumentation example.
This commit is contained in:
parent
f8ad82370f
commit
d4a3b1f282
16
README.md
16
README.md
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue