mirror of https://github.com/go-redis/redis.git
Merge pull request #427 from go-redis/fix/instrumentation-example
Add instrumentation example.
This commit is contained in:
commit
ecc6a4909b
16
README.md
16
README.md
|
@ -32,22 +32,6 @@ Import:
|
||||||
import "gopkg.in/redis.v5"
|
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
|
## Quickstart
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
|
@ -331,3 +331,21 @@ func ExampleScanCmd_Iterator() {
|
||||||
panic(err)
|
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"
|
"gopkg.in/redis.v5/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Scan(s string, val interface{}) error {
|
func Scan(s string, v interface{}) error {
|
||||||
switch v := val.(type) {
|
switch v := v.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return internal.RedisError("redis: Scan(nil)")
|
return internal.RedisError("redis: Scan(nil)")
|
||||||
case *string:
|
case *string:
|
||||||
|
@ -99,12 +99,10 @@ func Scan(s string, val interface{}) error {
|
||||||
case *bool:
|
case *bool:
|
||||||
*v = len(s) == 1 && s[0] == '1'
|
*v = len(s) == 1 && s[0] == '1'
|
||||||
return nil
|
return nil
|
||||||
|
case encoding.BinaryUnmarshaler:
|
||||||
|
return v.UnmarshalBinary([]byte(s))
|
||||||
default:
|
default:
|
||||||
if bu, ok := val.(encoding.BinaryUnmarshaler); ok {
|
return fmt.Errorf(
|
||||||
return bu.UnmarshalBinary([]byte(s))
|
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)
|
||||||
}
|
|
||||||
err := fmt.Errorf(
|
|
||||||
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", val)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue