File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -483,3 +483,51 @@ var _ = Describe("Conn", func() {
483
483
Expect (err ).NotTo (HaveOccurred ())
484
484
})
485
485
})
486
+
487
+ var _ = Describe ("Hook" , func () {
488
+ var client * redis.Client
489
+
490
+ BeforeEach (func () {
491
+ client = redis .NewClient (redisOptions ())
492
+ Expect (client .FlushDB (ctx ).Err ()).NotTo (HaveOccurred ())
493
+ })
494
+
495
+ AfterEach (func () {
496
+ err := client .Close ()
497
+ Expect (err ).NotTo (HaveOccurred ())
498
+ })
499
+
500
+ It ("fifo" , func () {
501
+ var res []string
502
+ client .AddHook (& hook {
503
+ processHook : func (hook redis.ProcessHook ) redis.ProcessHook {
504
+ return func (ctx context.Context , cmd redis.Cmder ) error {
505
+ res = append (res , "hook-1-process-start" )
506
+ err := hook (ctx , cmd )
507
+ res = append (res , "hook-1-process-end" )
508
+ return err
509
+ }
510
+ },
511
+ })
512
+ client .AddHook (& hook {
513
+ processHook : func (hook redis.ProcessHook ) redis.ProcessHook {
514
+ return func (ctx context.Context , cmd redis.Cmder ) error {
515
+ res = append (res , "hook-2-process-start" )
516
+ err := hook (ctx , cmd )
517
+ res = append (res , "hook-2-process-end" )
518
+ return err
519
+ }
520
+ },
521
+ })
522
+
523
+ err := client .Ping (ctx ).Err ()
524
+ Expect (err ).NotTo (HaveOccurred ())
525
+
526
+ Expect (res ).To (Equal ([]string {
527
+ "hook-1-process-start" ,
528
+ "hook-2-process-start" ,
529
+ "hook-2-process-end" ,
530
+ "hook-1-process-end" ,
531
+ }))
532
+ })
533
+ })
You can’t perform that action at this time.
0 commit comments