diff --git a/bench_test.go b/bench_test.go index 4af51842..5ddd82e4 100644 --- a/bench_test.go +++ b/bench_test.go @@ -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 { @@ -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) - } -} diff --git a/cluster.go b/cluster.go index b3e7a8cd..e3a344fc 100644 --- a/cluster.go +++ b/cluster.go @@ -723,21 +723,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { 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. func (c *ClusterClient) Options() *ClusterOptions { return c.opt @@ -1069,7 +1054,7 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) { for _, node := range nodes { _, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns() 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 { pipe := Pipeline{ - ctx: c.ctx, exec: c.processPipeline, } pipe.init() @@ -1259,7 +1243,6 @@ func (c *ClusterClient) checkMovedErr( // TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC. func (c *ClusterClient) TxPipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: c.processTxPipeline, } pipe.init() @@ -1616,7 +1599,7 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo { info := cmdsInfo[name] 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 } diff --git a/cluster_test.go b/cluster_test.go index 59fcef2f..42f95fbd 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -237,14 +237,6 @@ var _ = Describe("ClusterClient", func() { var client *redis.ClusterClient 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() { err := client.Get(ctx, "A").Err() Expect(err).To(Equal(redis.Nil)) diff --git a/pipeline.go b/pipeline.go index b9845ba3..52bd7213 100644 --- a/pipeline.go +++ b/pipeline.go @@ -38,7 +38,6 @@ type Pipeline struct { cmdable statefulCmdable - ctx context.Context exec pipelineExecer mu sync.Mutex diff --git a/race_test.go b/race_test.go index 6e4ab441..52181e06 100644 --- a/race_test.go +++ b/race_test.go @@ -290,13 +290,6 @@ var _ = Describe("races", func() { 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() { opt := redisClusterOptions() client := cluster.newClusterClient(ctx, opt) diff --git a/redis.go b/redis.go index 7248057d..d292d938 100644 --- a/redis.go +++ b/redis.go @@ -574,19 +574,6 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client { 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 { 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 { pipe := Pipeline{ - ctx: c.ctx, exec: c.processPipeline, } 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. func (c *Client) TxPipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: c.processTxPipeline, } pipe.init() @@ -757,7 +742,6 @@ func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder func (c *Conn) Pipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: c.processPipeline, } 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. func (c *Conn) TxPipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: c.processTxPipeline, } pipe.init() diff --git a/ring.go b/ring.go index 21a92649..9e24ec52 100644 --- a/ring.go +++ b/ring.go @@ -432,21 +432,6 @@ func NewRing(opt *RingOptions) *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. func (c *Ring) Do(ctx context.Context, args ...interface{}) *Cmd { 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 { pipe := Pipeline{ - ctx: c.ctx, exec: c.processPipeline, } pipe.init() @@ -638,7 +622,6 @@ func (c *Ring) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd func (c *Ring) TxPipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: c.processTxPipeline, } pipe.init() diff --git a/sentinel.go b/sentinel.go index 5cec0c53..6649a27b 100644 --- a/sentinel.go +++ b/sentinel.go @@ -256,7 +256,6 @@ func masterReplicaDialer( type SentinelClient struct { *baseClient hooks - ctx context.Context } func NewSentinelClient(opt *Options) *SentinelClient { @@ -266,24 +265,10 @@ func NewSentinelClient(opt *Options) *SentinelClient { opt: opt, connPool: newConnPool(opt), }, - ctx: context.Background(), } 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 { return c.hooks.process(ctx, cmd, c.baseClient.process) } diff --git a/tx.go b/tx.go index 079149fb..9381ed87 100644 --- a/tx.go +++ b/tx.go @@ -41,21 +41,6 @@ func (c *Tx) init() { 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 { 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. func (c *Tx) Pipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: func(ctx context.Context, cmds []Cmder) error { 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. func (c *Tx) TxPipeline() Pipeliner { pipe := Pipeline{ - ctx: c.ctx, exec: func(ctx context.Context, cmds []Cmder) error { return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline) }, diff --git a/universal.go b/universal.go index c89b3e5d..257a2055 100644 --- a/universal.go +++ b/universal.go @@ -182,7 +182,6 @@ func (o *UniversalOptions) Simple() *Options { // clients in different environments. type UniversalClient interface { Cmdable - Context() context.Context AddHook(Hook) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error Do(ctx context.Context, args ...interface{}) *Cmd