mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
fix example tests
This commit is contained in:
@ -23,33 +23,40 @@ func (redisHook) DialHook(hook redis.DialHook) redis.DialHook {
|
|||||||
|
|
||||||
func (redisHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
|
func (redisHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
|
||||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||||
fmt.Printf("starting processing: <%s>\n", cmd)
|
fmt.Printf("starting processing: <%v>\n", cmd.Args())
|
||||||
err := hook(ctx, cmd)
|
err := hook(ctx, cmd)
|
||||||
fmt.Printf("finished processing: <%s>\n", cmd)
|
fmt.Printf("finished processing: <%v>\n", cmd.Args())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (redisHook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
func (redisHook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
||||||
return func(ctx context.Context, cmds []redis.Cmder) error {
|
return func(ctx context.Context, cmds []redis.Cmder) error {
|
||||||
fmt.Printf("pipeline starting processing: %v\n", cmds)
|
names := make([]string, 0, len(cmds))
|
||||||
|
for _, cmd := range cmds {
|
||||||
|
names = append(names, fmt.Sprintf("%v", cmd.Args()))
|
||||||
|
}
|
||||||
|
fmt.Printf("pipeline starting processing: %v\n", names)
|
||||||
err := hook(ctx, cmds)
|
err := hook(ctx, cmds)
|
||||||
fmt.Printf("pipeline finished processing: %v\n", cmds)
|
fmt.Printf("pipeline finished processing: %v\n", names)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Example_instrumentation() {
|
func Example_instrumentation() {
|
||||||
rdb := redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: ":6379",
|
Addr: ":6379",
|
||||||
|
DisableIdentity: true,
|
||||||
})
|
})
|
||||||
rdb.AddHook(redisHook{})
|
rdb.AddHook(redisHook{})
|
||||||
|
|
||||||
rdb.Ping(ctx)
|
rdb.Ping(ctx)
|
||||||
// Output: starting processing: <ping: >
|
// Output: starting processing: <[ping]>
|
||||||
// dialing tcp :6379
|
// dialing tcp :6379
|
||||||
// finished dialing tcp :6379
|
// finished dialing tcp :6379
|
||||||
// finished processing: <ping: PONG>
|
// starting processing: <[hello 3]>
|
||||||
|
// finished processing: <[hello 3]>
|
||||||
|
// finished processing: <[ping]>
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExamplePipeline_instrumentation() {
|
func ExamplePipeline_instrumentation() {
|
||||||
@ -64,9 +71,10 @@ func ExamplePipeline_instrumentation() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
// Output: pipeline starting processing: [ping: ping: ]
|
// Output: pipeline starting processing: [ping: ping: ]
|
||||||
|
// Output: pipeline starting processing: [[ping] [ping]]
|
||||||
// dialing tcp :6379
|
// dialing tcp :6379
|
||||||
// finished dialing tcp :6379
|
// finished dialing tcp :6379
|
||||||
// pipeline finished processing: [ping: PONG ping: PONG]
|
// pipeline finished processing: [[ping] [ping]]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleClient_Watch_instrumentation() {
|
func ExampleClient_Watch_instrumentation() {
|
||||||
@ -81,14 +89,14 @@ func ExampleClient_Watch_instrumentation() {
|
|||||||
return nil
|
return nil
|
||||||
}, "foo")
|
}, "foo")
|
||||||
// Output:
|
// Output:
|
||||||
// starting processing: <watch foo: >
|
// starting processing: <[watch foo]>
|
||||||
// dialing tcp :6379
|
// dialing tcp :6379
|
||||||
// finished dialing tcp :6379
|
// finished dialing tcp :6379
|
||||||
// finished processing: <watch foo: OK>
|
// finished processing: <[watch foo]>
|
||||||
// starting processing: <ping: >
|
// starting processing: <[ping]>
|
||||||
// finished processing: <ping: PONG>
|
// finished processing: <[ping]>
|
||||||
// starting processing: <ping: >
|
// starting processing: <[ping]>
|
||||||
// finished processing: <ping: PONG>
|
// finished processing: <[ping]>
|
||||||
// starting processing: <unwatch: >
|
// starting processing: <[unwatch]>
|
||||||
// finished processing: <unwatch: OK>
|
// finished processing: <[unwatch]>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user