forked from mirror/redis
Merge pull request #1088 from go-redis/fix/tweak-hooks
Don't return a context from After* hooks
This commit is contained in:
commit
850dea52a1
|
@ -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() {
|
||||
|
|
10
redis.go
10
redis.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue