mirror of https://github.com/go-redis/redis.git
Don't return a context from After* hooks
This commit is contained in:
parent
8315cd06b3
commit
9fd4e69ce4
|
@ -16,9 +16,9 @@ func (redisHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Co
|
||||||
return ctx, nil
|
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)
|
fmt.Printf("finished processing: <%s>\n", cmd)
|
||||||
return ctx, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
|
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
|
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)
|
fmt.Printf("pipeline finished processing: %v\n", cmds)
|
||||||
return ctx, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Example_instrumentation() {
|
func Example_instrumentation() {
|
||||||
|
|
10
redis.go
10
redis.go
|
@ -22,10 +22,10 @@ func SetLogger(logger *log.Logger) {
|
||||||
|
|
||||||
type Hook interface {
|
type Hook interface {
|
||||||
BeforeProcess(ctx context.Context, cmd Cmder) (context.Context, error)
|
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)
|
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 {
|
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) {
|
func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) {
|
||||||
var firstErr error
|
var firstErr error
|
||||||
for _, h := range hs.hooks {
|
for _, h := range hs.hooks {
|
||||||
var err error
|
err := h.AfterProcess(ctx, cmd)
|
||||||
ctx, err = h.AfterProcess(ctx, cmd)
|
|
||||||
if err != nil && firstErr == nil {
|
if err != nil && firstErr == nil {
|
||||||
firstErr = err
|
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) {
|
func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) {
|
||||||
var firstErr error
|
var firstErr error
|
||||||
for _, h := range hs.hooks {
|
for _, h := range hs.hooks {
|
||||||
var err error
|
err := h.AfterProcessPipeline(ctx, cmds)
|
||||||
ctx, err = h.AfterProcessPipeline(ctx, cmds)
|
|
||||||
if err != nil && firstErr == nil {
|
if err != nil && firstErr == nil {
|
||||||
firstErr = err
|
firstErr = err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue