@@ -23,33 +23,40 @@ func (redisHook) DialHook(hook redis.DialHook) redis.DialHook {
2323
2424func (redisHook ) ProcessHook (hook redis.ProcessHook ) redis.ProcessHook {
2525 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 () )
2727 err := hook (ctx , cmd )
28- fmt .Printf ("finished processing: <%s >\n " , cmd )
28+ fmt .Printf ("finished processing: <%v >\n " , cmd . Args () )
2929 return err
3030 }
3131}
3232
3333func (redisHook ) ProcessPipelineHook (hook redis.ProcessPipelineHook ) redis.ProcessPipelineHook {
3434 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 )
3640 err := hook (ctx , cmds )
37- fmt .Printf ("pipeline finished processing: %v\n " , cmds )
41+ fmt .Printf ("pipeline finished processing: %v\n " , names )
3842 return err
3943 }
4044}
4145
4246func Example_instrumentation () {
4347 rdb := redis .NewClient (& redis.Options {
44- Addr : ":6379" ,
48+ Addr : ":6379" ,
49+ DisableIdentity : true ,
4550 })
4651 rdb .AddHook (redisHook {})
4752
4853 rdb .Ping (ctx )
49- // Output: starting processing: <ping: >
54+ // Output: starting processing: <[ ping] >
5055 // dialing tcp :6379
5156 // finished dialing tcp :6379
52- // finished processing: <ping: PONG>
57+ // starting processing: <[hello 3]>
58+ // finished processing: <[hello 3]>
59+ // finished processing: <[ping]>
5360}
5461
5562func ExamplePipeline_instrumentation () {
@@ -64,9 +71,10 @@ func ExamplePipeline_instrumentation() {
6471 return nil
6572 })
6673 // Output: pipeline starting processing: [ping: ping: ]
74+ // Output: pipeline starting processing: [[ping] [ping]]
6775 // dialing tcp :6379
6876 // finished dialing tcp :6379
69- // pipeline finished processing: [ping: PONG ping: PONG ]
77+ // pipeline finished processing: [[ ping] [ ping] ]
7078}
7179
7280func ExampleClient_Watch_instrumentation () {
@@ -81,14 +89,14 @@ func ExampleClient_Watch_instrumentation() {
8189 return nil
8290 }, "foo" )
8391 // Output:
84- // starting processing: <watch foo: >
92+ // starting processing: <[ watch foo] >
8593 // dialing tcp :6379
8694 // 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] >
94102}
0 commit comments