mirror of https://github.com/go-redis/redis.git
fix race detector checking failed about hook
This commit is contained in:
parent
c3098d5f7e
commit
a0e3d7e82f
13
redis.go
13
redis.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
type hooksMixin struct {
|
type hooksMixin struct {
|
||||||
|
mu sync.RWMutex
|
||||||
slice []Hook
|
slice []Hook
|
||||||
initial hooks
|
initial hooks
|
||||||
current hooks
|
current hooks
|
||||||
|
@ -116,6 +118,9 @@ func (hs *hooksMixin) AddHook(hook Hook) {
|
||||||
func (hs *hooksMixin) chain() {
|
func (hs *hooksMixin) chain() {
|
||||||
hs.initial.setDefaults()
|
hs.initial.setDefaults()
|
||||||
|
|
||||||
|
hs.mu.Lock()
|
||||||
|
defer hs.mu.Unlock()
|
||||||
|
|
||||||
hs.current.dial = hs.initial.dial
|
hs.current.dial = hs.initial.dial
|
||||||
hs.current.process = hs.initial.process
|
hs.current.process = hs.initial.process
|
||||||
hs.current.pipeline = hs.initial.pipeline
|
hs.current.pipeline = hs.initial.pipeline
|
||||||
|
@ -165,18 +170,26 @@ func (hs *hooksMixin) withProcessPipelineHook(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
|
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
|
hs.mu.RLock()
|
||||||
|
defer hs.mu.RUnlock()
|
||||||
return hs.current.dial(ctx, network, addr)
|
return hs.current.dial(ctx, network, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *hooksMixin) processHook(ctx context.Context, cmd Cmder) error {
|
func (hs *hooksMixin) processHook(ctx context.Context, cmd Cmder) error {
|
||||||
|
hs.mu.RLock()
|
||||||
|
defer hs.mu.RUnlock()
|
||||||
return hs.current.process(ctx, cmd)
|
return hs.current.process(ctx, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *hooksMixin) processPipelineHook(ctx context.Context, cmds []Cmder) error {
|
func (hs *hooksMixin) processPipelineHook(ctx context.Context, cmds []Cmder) error {
|
||||||
|
hs.mu.RLock()
|
||||||
|
defer hs.mu.RUnlock()
|
||||||
return hs.current.pipeline(ctx, cmds)
|
return hs.current.pipeline(ctx, cmds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *hooksMixin) processTxPipelineHook(ctx context.Context, cmds []Cmder) error {
|
func (hs *hooksMixin) processTxPipelineHook(ctx context.Context, cmds []Cmder) error {
|
||||||
|
hs.mu.RLock()
|
||||||
|
defer hs.mu.RUnlock()
|
||||||
return hs.current.txPipeline(ctx, cmds)
|
return hs.current.txPipeline(ctx, cmds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue