2016-11-30 13:39:14 +03:00
|
|
|
package redis_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-02-18 17:42:34 +03:00
|
|
|
"github.com/go-redis/redis"
|
2016-11-30 13:39:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func Example_instrumentation() {
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb := redis.NewClient(&redis.Options{
|
2018-01-20 13:26:33 +03:00
|
|
|
Addr: ":6379",
|
2016-11-30 13:39:14 +03:00
|
|
|
})
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb.WrapProcess(func(old func(cmd redis.Cmder) error) func(cmd redis.Cmder) error {
|
2018-01-20 13:26:33 +03:00
|
|
|
return func(cmd redis.Cmder) error {
|
|
|
|
fmt.Printf("starting processing: <%s>\n", cmd)
|
|
|
|
err := old(cmd)
|
|
|
|
fmt.Printf("finished processing: <%s>\n", cmd)
|
|
|
|
return err
|
|
|
|
}
|
2016-11-30 13:39:14 +03:00
|
|
|
})
|
|
|
|
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb.Ping()
|
2018-01-20 13:26:33 +03:00
|
|
|
// Output: starting processing: <ping: >
|
|
|
|
// finished processing: <ping: PONG>
|
2016-11-30 13:39:14 +03:00
|
|
|
}
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
func ExamplePipeline_instrumentation() {
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb := redis.NewClient(&redis.Options{
|
2018-01-20 13:26:33 +03:00
|
|
|
Addr: ":6379",
|
|
|
|
})
|
2016-11-30 13:39:14 +03:00
|
|
|
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb.WrapProcessPipeline(func(old func([]redis.Cmder) error) func([]redis.Cmder) error {
|
2018-01-20 13:26:33 +03:00
|
|
|
return func(cmds []redis.Cmder) error {
|
|
|
|
fmt.Printf("pipeline starting processing: %v\n", cmds)
|
|
|
|
err := old(cmds)
|
|
|
|
fmt.Printf("pipeline finished processing: %v\n", cmds)
|
2016-11-30 13:39:14 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
})
|
2018-01-20 13:26:33 +03:00
|
|
|
|
2018-08-12 11:19:25 +03:00
|
|
|
redisdb.Pipelined(func(pipe redis.Pipeliner) error {
|
2018-01-20 13:26:33 +03:00
|
|
|
pipe.Ping()
|
|
|
|
pipe.Ping()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
// Output: pipeline starting processing: [ping: ping: ]
|
|
|
|
// pipeline finished processing: [ping: PONG ping: PONG]
|
2016-11-30 13:39:14 +03:00
|
|
|
}
|