mirror of https://github.com/go-redis/redis.git
chore: remove WithContext
This commit is contained in:
parent
0768a688c6
commit
4ddd7d1803
|
@ -273,36 +273,6 @@ func BenchmarkXRead(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSink *redis.Client
|
|
||||||
|
|
||||||
func BenchmarkWithContext(b *testing.B) {
|
|
||||||
ctx := context.Background()
|
|
||||||
rdb := benchmarkRedisClient(ctx, 10)
|
|
||||||
defer rdb.Close()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.ReportAllocs()
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
clientSink = rdb.WithContext(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var ringSink *redis.Ring
|
|
||||||
|
|
||||||
func BenchmarkRingWithContext(b *testing.B) {
|
|
||||||
ctx := context.Background()
|
|
||||||
rdb := redis.NewRing(&redis.RingOptions{})
|
|
||||||
defer rdb.Close()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.ReportAllocs()
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ringSink = rdb.WithContext(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
func newClusterScenario() *clusterScenario {
|
func newClusterScenario() *clusterScenario {
|
||||||
|
@ -395,18 +365,3 @@ func BenchmarkClusterSetString(b *testing.B) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var clusterSink *redis.ClusterClient
|
|
||||||
|
|
||||||
func BenchmarkClusterWithContext(b *testing.B) {
|
|
||||||
ctx := context.Background()
|
|
||||||
rdb := redis.NewClusterClient(&redis.ClusterOptions{})
|
|
||||||
defer rdb.Close()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.ReportAllocs()
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
clusterSink = rdb.WithContext(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
21
cluster.go
21
cluster.go
|
@ -723,21 +723,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) Context() context.Context {
|
|
||||||
return c.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ClusterClient) WithContext(ctx context.Context) *ClusterClient {
|
|
||||||
if ctx == nil {
|
|
||||||
panic("nil context")
|
|
||||||
}
|
|
||||||
clone := *c
|
|
||||||
clone.cmdable = clone.Process
|
|
||||||
clone.hooks.lock()
|
|
||||||
clone.ctx = ctx
|
|
||||||
return &clone
|
|
||||||
}
|
|
||||||
|
|
||||||
// Options returns read-only Options that were used to create the client.
|
// Options returns read-only Options that were used to create the client.
|
||||||
func (c *ClusterClient) Options() *ClusterOptions {
|
func (c *ClusterClient) Options() *ClusterOptions {
|
||||||
return c.opt
|
return c.opt
|
||||||
|
@ -1069,7 +1054,7 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
|
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internal.Logger.Printf(c.Context(), "ReapStaleConns failed: %s", err)
|
internal.Logger.Printf(context.TODO(), "ReapStaleConns failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1077,7 +1062,6 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
|
||||||
|
|
||||||
func (c *ClusterClient) Pipeline() Pipeliner {
|
func (c *ClusterClient) Pipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processPipeline,
|
exec: c.processPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -1259,7 +1243,6 @@ func (c *ClusterClient) checkMovedErr(
|
||||||
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
||||||
func (c *ClusterClient) TxPipeline() Pipeliner {
|
func (c *ClusterClient) TxPipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processTxPipeline,
|
exec: c.processTxPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -1616,7 +1599,7 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
|
||||||
|
|
||||||
info := cmdsInfo[name]
|
info := cmdsInfo[name]
|
||||||
if info == nil {
|
if info == nil {
|
||||||
internal.Logger.Printf(c.Context(), "info for cmd=%s not found", name)
|
internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name)
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,14 +237,6 @@ var _ = Describe("ClusterClient", func() {
|
||||||
var client *redis.ClusterClient
|
var client *redis.ClusterClient
|
||||||
|
|
||||||
assertClusterClient := func() {
|
assertClusterClient := func() {
|
||||||
It("supports WithContext", func() {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
cancel()
|
|
||||||
|
|
||||||
err := client.Ping(ctx).Err()
|
|
||||||
Expect(err).To(MatchError("context canceled"))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("should GET/SET/DEL", func() {
|
It("should GET/SET/DEL", func() {
|
||||||
err := client.Get(ctx, "A").Err()
|
err := client.Get(ctx, "A").Err()
|
||||||
Expect(err).To(Equal(redis.Nil))
|
Expect(err).To(Equal(redis.Nil))
|
||||||
|
|
|
@ -38,7 +38,6 @@ type Pipeline struct {
|
||||||
cmdable
|
cmdable
|
||||||
statefulCmdable
|
statefulCmdable
|
||||||
|
|
||||||
ctx context.Context
|
|
||||||
exec pipelineExecer
|
exec pipelineExecer
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
|
@ -290,13 +290,6 @@ var _ = Describe("races", func() {
|
||||||
Expect(atomic.LoadUint32(&received)).To(Equal(uint32(C * N)))
|
Expect(atomic.LoadUint32(&received)).To(Equal(uint32(C * N)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should WithContext", func() {
|
|
||||||
perform(C, func(_ int) {
|
|
||||||
err := client.WithContext(ctx).Ping(ctx).Err()
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
It("should abort on context timeout", func() {
|
It("should abort on context timeout", func() {
|
||||||
opt := redisClusterOptions()
|
opt := redisClusterOptions()
|
||||||
client := cluster.newClusterClient(ctx, opt)
|
client := cluster.newClusterClient(ctx, opt)
|
||||||
|
|
17
redis.go
17
redis.go
|
@ -574,19 +574,6 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Context() context.Context {
|
|
||||||
return c.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) WithContext(ctx context.Context) *Client {
|
|
||||||
if ctx == nil {
|
|
||||||
panic("nil context")
|
|
||||||
}
|
|
||||||
clone := c.clone()
|
|
||||||
clone.ctx = ctx
|
|
||||||
return clone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) Conn(ctx context.Context) *Conn {
|
func (c *Client) Conn(ctx context.Context) *Conn {
|
||||||
return newConn(ctx, c.opt, pool.NewStickyConnPool(c.connPool))
|
return newConn(ctx, c.opt, pool.NewStickyConnPool(c.connPool))
|
||||||
}
|
}
|
||||||
|
@ -629,7 +616,6 @@ func (c *Client) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
|
||||||
|
|
||||||
func (c *Client) Pipeline() Pipeliner {
|
func (c *Client) Pipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processPipeline,
|
exec: c.processPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -643,7 +629,6 @@ func (c *Client) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]C
|
||||||
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
||||||
func (c *Client) TxPipeline() Pipeliner {
|
func (c *Client) TxPipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processTxPipeline,
|
exec: c.processTxPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -757,7 +742,6 @@ func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
|
||||||
|
|
||||||
func (c *Conn) Pipeline() Pipeliner {
|
func (c *Conn) Pipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processPipeline,
|
exec: c.processPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -771,7 +755,6 @@ func (c *Conn) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
|
||||||
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
||||||
func (c *Conn) TxPipeline() Pipeliner {
|
func (c *Conn) TxPipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processTxPipeline,
|
exec: c.processTxPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
|
17
ring.go
17
ring.go
|
@ -432,21 +432,6 @@ func NewRing(opt *RingOptions) *Ring {
|
||||||
return &ring
|
return &ring
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Ring) Context() context.Context {
|
|
||||||
return c.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Ring) WithContext(ctx context.Context) *Ring {
|
|
||||||
if ctx == nil {
|
|
||||||
panic("nil context")
|
|
||||||
}
|
|
||||||
clone := *c
|
|
||||||
clone.cmdable = clone.Process
|
|
||||||
clone.hooks.lock()
|
|
||||||
clone.ctx = ctx
|
|
||||||
return &clone
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do creates a Cmd from the args and processes the cmd.
|
// Do creates a Cmd from the args and processes the cmd.
|
||||||
func (c *Ring) Do(ctx context.Context, args ...interface{}) *Cmd {
|
func (c *Ring) Do(ctx context.Context, args ...interface{}) *Cmd {
|
||||||
cmd := NewCmd(ctx, args...)
|
cmd := NewCmd(ctx, args...)
|
||||||
|
@ -619,7 +604,6 @@ func (c *Ring) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
|
||||||
|
|
||||||
func (c *Ring) Pipeline() Pipeliner {
|
func (c *Ring) Pipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processPipeline,
|
exec: c.processPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
@ -638,7 +622,6 @@ func (c *Ring) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
|
||||||
|
|
||||||
func (c *Ring) TxPipeline() Pipeliner {
|
func (c *Ring) TxPipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: c.processTxPipeline,
|
exec: c.processTxPipeline,
|
||||||
}
|
}
|
||||||
pipe.init()
|
pipe.init()
|
||||||
|
|
15
sentinel.go
15
sentinel.go
|
@ -256,7 +256,6 @@ func masterReplicaDialer(
|
||||||
type SentinelClient struct {
|
type SentinelClient struct {
|
||||||
*baseClient
|
*baseClient
|
||||||
hooks
|
hooks
|
||||||
ctx context.Context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSentinelClient(opt *Options) *SentinelClient {
|
func NewSentinelClient(opt *Options) *SentinelClient {
|
||||||
|
@ -266,24 +265,10 @@ func NewSentinelClient(opt *Options) *SentinelClient {
|
||||||
opt: opt,
|
opt: opt,
|
||||||
connPool: newConnPool(opt),
|
connPool: newConnPool(opt),
|
||||||
},
|
},
|
||||||
ctx: context.Background(),
|
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SentinelClient) Context() context.Context {
|
|
||||||
return c.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SentinelClient) WithContext(ctx context.Context) *SentinelClient {
|
|
||||||
if ctx == nil {
|
|
||||||
panic("nil context")
|
|
||||||
}
|
|
||||||
clone := *c
|
|
||||||
clone.ctx = ctx
|
|
||||||
return &clone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error {
|
func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error {
|
||||||
return c.hooks.process(ctx, cmd, c.baseClient.process)
|
return c.hooks.process(ctx, cmd, c.baseClient.process)
|
||||||
}
|
}
|
||||||
|
|
17
tx.go
17
tx.go
|
@ -41,21 +41,6 @@ func (c *Tx) init() {
|
||||||
c.statefulCmdable = c.Process
|
c.statefulCmdable = c.Process
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Tx) Context() context.Context {
|
|
||||||
return c.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Tx) WithContext(ctx context.Context) *Tx {
|
|
||||||
if ctx == nil {
|
|
||||||
panic("nil context")
|
|
||||||
}
|
|
||||||
clone := *c
|
|
||||||
clone.init()
|
|
||||||
clone.hooks.lock()
|
|
||||||
clone.ctx = ctx
|
|
||||||
return &clone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Tx) Process(ctx context.Context, cmd Cmder) error {
|
func (c *Tx) Process(ctx context.Context, cmd Cmder) error {
|
||||||
return c.hooks.process(ctx, cmd, c.baseClient.process)
|
return c.hooks.process(ctx, cmd, c.baseClient.process)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +94,6 @@ func (c *Tx) Unwatch(ctx context.Context, keys ...string) *StatusCmd {
|
||||||
// Pipeline creates a pipeline. Usually it is more convenient to use Pipelined.
|
// Pipeline creates a pipeline. Usually it is more convenient to use Pipelined.
|
||||||
func (c *Tx) Pipeline() Pipeliner {
|
func (c *Tx) Pipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: func(ctx context.Context, cmds []Cmder) error {
|
exec: func(ctx context.Context, cmds []Cmder) error {
|
||||||
return c.hooks.processPipeline(ctx, cmds, c.baseClient.processPipeline)
|
return c.hooks.processPipeline(ctx, cmds, c.baseClient.processPipeline)
|
||||||
},
|
},
|
||||||
|
@ -139,7 +123,6 @@ func (c *Tx) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
|
||||||
// TxPipeline creates a pipeline. Usually it is more convenient to use TxPipelined.
|
// TxPipeline creates a pipeline. Usually it is more convenient to use TxPipelined.
|
||||||
func (c *Tx) TxPipeline() Pipeliner {
|
func (c *Tx) TxPipeline() Pipeliner {
|
||||||
pipe := Pipeline{
|
pipe := Pipeline{
|
||||||
ctx: c.ctx,
|
|
||||||
exec: func(ctx context.Context, cmds []Cmder) error {
|
exec: func(ctx context.Context, cmds []Cmder) error {
|
||||||
return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline)
|
return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline)
|
||||||
},
|
},
|
||||||
|
|
|
@ -182,7 +182,6 @@ func (o *UniversalOptions) Simple() *Options {
|
||||||
// clients in different environments.
|
// clients in different environments.
|
||||||
type UniversalClient interface {
|
type UniversalClient interface {
|
||||||
Cmdable
|
Cmdable
|
||||||
Context() context.Context
|
|
||||||
AddHook(Hook)
|
AddHook(Hook)
|
||||||
Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error
|
Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error
|
||||||
Do(ctx context.Context, args ...interface{}) *Cmd
|
Do(ctx context.Context, args ...interface{}) *Cmd
|
||||||
|
|
Loading…
Reference in New Issue