Merge pull request #1088 from go-redis/fix/tweak-hooks

Don't return a context from After* hooks
This commit is contained in:
Vladimir Mihailenco 2019-07-11 12:27:27 +03:00 committed by GitHub
commit 850dea52a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -16,9 +16,9 @@ func (redisHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Co
return ctx, nil
}
func (redisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
func (redisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error {
fmt.Printf("finished processing: <%s>\n", cmd)
return ctx, nil
return nil
}
func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
@ -26,9 +26,9 @@ func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder)
return ctx, nil
}
func (redisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
func (redisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error {
fmt.Printf("pipeline finished processing: %v\n", cmds)
return ctx, nil
return nil
}
func Example_instrumentation() {

View File

@ -22,10 +22,10 @@ func SetLogger(logger *log.Logger) {
type Hook interface {
BeforeProcess(ctx context.Context, cmd Cmder) (context.Context, error)
AfterProcess(ctx context.Context, cmd Cmder) (context.Context, error)
AfterProcess(ctx context.Context, cmd Cmder) error
BeforeProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error)
AfterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error)
AfterProcessPipeline(ctx context.Context, cmds []Cmder) error
}
type hooks struct {
@ -68,8 +68,7 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context,
func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcess(ctx, cmd)
err := h.AfterProcess(ctx, cmd)
if err != nil && firstErr == nil {
firstErr = err
}
@ -109,8 +108,7 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex
func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcessPipeline(ctx, cmds)
err := h.AfterProcessPipeline(ctx, cmds)
if err != nil && firstErr == nil {
firstErr = err
}