Merge pull request #1477 from go-redis/fix/hooks-lifo

Change hooks to be LIFO
This commit is contained in:
Vladimir Mihailenco 2020-09-10 09:43:29 +03:00 committed by GitHub
commit fb80d4211a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -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 { func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) error {
var firstErr error var firstErr error
for _, h := range hs.hooks { for i := len(hs.hooks) - 1; i >= 0; i-- {
err := h.AfterProcess(ctx, cmd) h := hs.hooks[i]
if err != nil && firstErr == nil { if err := h.AfterProcess(ctx, cmd); err != nil && firstErr == nil {
firstErr = err 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 { func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error {
var firstErr error var firstErr error
for _, h := range hs.hooks { for i := len(hs.hooks) - 1; i >= 0; i-- {
err := h.AfterProcessPipeline(ctx, cmds) h := hs.hooks[i]
if err != nil && firstErr == nil { if err := h.AfterProcessPipeline(ctx, cmds); err != nil && firstErr == nil {
firstErr = err firstErr = err
} }
} }