From 5aaa6c62079e2c2551322fd66c57daaada4fa6b5 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 10 Sep 2020 09:22:51 +0300 Subject: [PATCH] Change hooks to be LIFO --- redis.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/redis.go b/redis.go index 2894e6a..198d4a7 100644 --- a/redis.go +++ b/redis.go @@ -77,9 +77,9 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context, func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) error { var firstErr error - for _, h := range hs.hooks { - err := h.AfterProcess(ctx, cmd) - if err != nil && firstErr == nil { + for i := len(hs.hooks) - 1; i >= 0; i-- { + h := hs.hooks[i] + if err := h.AfterProcess(ctx, cmd); err != nil && firstErr == nil { firstErr = err } } @@ -118,9 +118,9 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error { var firstErr error - for _, h := range hs.hooks { - err := h.AfterProcessPipeline(ctx, cmds) - if err != nil && firstErr == nil { + for i := len(hs.hooks) - 1; i >= 0; i-- { + h := hs.hooks[i] + if err := h.AfterProcessPipeline(ctx, cmds); err != nil && firstErr == nil { firstErr = err } }