From 0ed4a4420fddcbe897b3884ef637ece53ccc55b8 Mon Sep 17 00:00:00 2001 From: monkey Date: Sat, 21 Jan 2023 00:02:44 +0800 Subject: [PATCH] fix: fix the withHook func Signed-off-by: monkey --- redis.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/redis.go b/redis.go index b7f4ff36..7cd65a2f 100644 --- a/redis.go +++ b/redis.go @@ -158,8 +158,8 @@ func (hs *hooks) setDefaultHook(d defaultHook) { } func (hs *hooks) withProcessHook(ctx context.Context, cmd Cmder, hook ProcessHook) error { - for _, h := range hs.slice { - if wrapped := h.ProcessHook(hook); wrapped != nil { + for i := len(hs.slice) - 1; i >= 0; i-- { + if wrapped := hs.slice[i].ProcessHook(hook); wrapped != nil { hook = wrapped } } @@ -169,8 +169,8 @@ func (hs *hooks) withProcessHook(ctx context.Context, cmd Cmder, hook ProcessHoo func (hs *hooks) withProcessPipelineHook( ctx context.Context, cmds []Cmder, hook ProcessPipelineHook, ) error { - for _, h := range hs.slice { - if wrapped := h.ProcessPipelineHook(hook); wrapped != nil { + for i := len(hs.slice) - 1; i >= 0; i-- { + if wrapped := hs.slice[i].ProcessPipelineHook(hook); wrapped != nil { hook = wrapped } }