1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

Replace Wrap* with hooks that support context

This commit is contained in:
Vladimir Mihailenco
2019-05-31 16:36:57 +03:00
parent b902746d7b
commit 8476dfea4a
10 changed files with 423 additions and 349 deletions

View File

@ -1,6 +1,7 @@
package redis
import (
"context"
"crypto/tls"
"errors"
"net"
@ -93,7 +94,6 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
onClose: failover.Close,
},
}
c.baseClient.init()
c.cmdable.setProcessor(c.Process)
return &c
@ -103,6 +103,8 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
type SentinelClient struct {
baseClient
ctx context.Context
}
func NewSentinelClient(opt *Options) *SentinelClient {
@ -113,10 +115,34 @@ func NewSentinelClient(opt *Options) *SentinelClient {
connPool: newConnPool(opt),
},
}
c.baseClient.init()
return c
}
func (c *SentinelClient) Context() context.Context {
if c.ctx != nil {
return c.ctx
}
return context.Background()
}
func (c *SentinelClient) WithContext(ctx context.Context) *SentinelClient {
if ctx == nil {
panic("nil context")
}
c2 := c.clone()
c2.ctx = ctx
return c2
}
func (c *SentinelClient) clone() *SentinelClient {
clone := *c
return &clone
}
func (c *SentinelClient) Process(cmd Cmder) error {
return c.baseClient.process(cmd)
}
func (c *SentinelClient) pubSub() *PubSub {
pubsub := &PubSub{
opt: c.opt,