mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add instrumentation example.
This commit is contained in:
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user