@@ -23,33 +23,40 @@ func (redisHook) DialHook(hook redis.DialHook) redis.DialHook {
23
23
24
24
func (redisHook ) ProcessHook (hook redis.ProcessHook ) redis.ProcessHook {
25
25
return func (ctx context.Context , cmd redis.Cmder ) error {
26
- fmt .Printf ("starting processing: <%s >\n " , cmd )
26
+ fmt .Printf ("starting processing: <%v >\n " , cmd . Args () )
27
27
err := hook (ctx , cmd )
28
- fmt .Printf ("finished processing: <%s >\n " , cmd )
28
+ fmt .Printf ("finished processing: <%v >\n " , cmd . Args () )
29
29
return err
30
30
}
31
31
}
32
32
33
33
func (redisHook ) ProcessPipelineHook (hook redis.ProcessPipelineHook ) redis.ProcessPipelineHook {
34
34
return func (ctx context.Context , cmds []redis.Cmder ) error {
35
- fmt .Printf ("pipeline starting processing: %v\n " , cmds )
35
+ names := make ([]string , 0 , len (cmds ))
36
+ for _ , cmd := range cmds {
37
+ names = append (names , fmt .Sprintf ("%v" , cmd .Args ()))
38
+ }
39
+ fmt .Printf ("pipeline starting processing: %v\n " , names )
36
40
err := hook (ctx , cmds )
37
- fmt .Printf ("pipeline finished processing: %v\n " , cmds )
41
+ fmt .Printf ("pipeline finished processing: %v\n " , names )
38
42
return err
39
43
}
40
44
}
41
45
42
46
func Example_instrumentation () {
43
47
rdb := redis .NewClient (& redis.Options {
44
- Addr : ":6379" ,
48
+ Addr : ":6379" ,
49
+ DisableIdentity : true ,
45
50
})
46
51
rdb .AddHook (redisHook {})
47
52
48
53
rdb .Ping (ctx )
49
- // Output: starting processing: <ping: >
54
+ // Output: starting processing: <[ ping] >
50
55
// dialing tcp :6379
51
56
// finished dialing tcp :6379
52
- // finished processing: <ping: PONG>
57
+ // starting processing: <[hello 3]>
58
+ // finished processing: <[hello 3]>
59
+ // finished processing: <[ping]>
53
60
}
54
61
55
62
func ExamplePipeline_instrumentation () {
@@ -64,9 +71,10 @@ func ExamplePipeline_instrumentation() {
64
71
return nil
65
72
})
66
73
// Output: pipeline starting processing: [ping: ping: ]
74
+ // Output: pipeline starting processing: [[ping] [ping]]
67
75
// dialing tcp :6379
68
76
// finished dialing tcp :6379
69
- // pipeline finished processing: [ping: PONG ping: PONG ]
77
+ // pipeline finished processing: [[ ping] [ ping] ]
70
78
}
71
79
72
80
func ExampleClient_Watch_instrumentation () {
@@ -81,14 +89,14 @@ func ExampleClient_Watch_instrumentation() {
81
89
return nil
82
90
}, "foo" )
83
91
// Output:
84
- // starting processing: <watch foo: >
92
+ // starting processing: <[ watch foo] >
85
93
// dialing tcp :6379
86
94
// finished dialing tcp :6379
87
- // finished processing: <watch foo: OK >
88
- // starting processing: <ping: >
89
- // finished processing: <ping: PONG >
90
- // starting processing: <ping: >
91
- // finished processing: <ping: PONG >
92
- // starting processing: <unwatch: >
93
- // finished processing: <unwatch: OK >
95
+ // finished processing: <[ watch foo] >
96
+ // starting processing: <[ ping] >
97
+ // finished processing: <[ ping] >
98
+ // starting processing: <[ ping] >
99
+ // finished processing: <[ ping] >
100
+ // starting processing: <[ unwatch] >
101
+ // finished processing: <[ unwatch] >
94
102
}
0 commit comments