Skip to content

Commit 4ddd7d1

Browse files
committed
chore: remove WithContext
1 parent 0768a68 commit 4ddd7d1

File tree

10 files changed

+2
-147
lines changed

10 files changed

+2
-147
lines changed

bench_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -273,36 +273,6 @@ func BenchmarkXRead(b *testing.B) {
273273
})
274274
}
275275

276-
var clientSink *redis.Client
277-
278-
func BenchmarkWithContext(b *testing.B) {
279-
ctx := context.Background()
280-
rdb := benchmarkRedisClient(ctx, 10)
281-
defer rdb.Close()
282-
283-
b.ResetTimer()
284-
b.ReportAllocs()
285-
286-
for i := 0; i < b.N; i++ {
287-
clientSink = rdb.WithContext(ctx)
288-
}
289-
}
290-
291-
var ringSink *redis.Ring
292-
293-
func BenchmarkRingWithContext(b *testing.B) {
294-
ctx := context.Background()
295-
rdb := redis.NewRing(&redis.RingOptions{})
296-
defer rdb.Close()
297-
298-
b.ResetTimer()
299-
b.ReportAllocs()
300-
301-
for i := 0; i < b.N; i++ {
302-
ringSink = rdb.WithContext(ctx)
303-
}
304-
}
305-
306276
//------------------------------------------------------------------------------
307277

308278
func newClusterScenario() *clusterScenario {
@@ -395,18 +365,3 @@ func BenchmarkClusterSetString(b *testing.B) {
395365
}
396366
})
397367
}
398-
399-
var clusterSink *redis.ClusterClient
400-
401-
func BenchmarkClusterWithContext(b *testing.B) {
402-
ctx := context.Background()
403-
rdb := redis.NewClusterClient(&redis.ClusterOptions{})
404-
defer rdb.Close()
405-
406-
b.ResetTimer()
407-
b.ReportAllocs()
408-
409-
for i := 0; i < b.N; i++ {
410-
clusterSink = rdb.WithContext(ctx)
411-
}
412-
}

cluster.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -723,21 +723,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
723723
return c
724724
}
725725

726-
func (c *ClusterClient) Context() context.Context {
727-
return c.ctx
728-
}
729-
730-
func (c *ClusterClient) WithContext(ctx context.Context) *ClusterClient {
731-
if ctx == nil {
732-
panic("nil context")
733-
}
734-
clone := *c
735-
clone.cmdable = clone.Process
736-
clone.hooks.lock()
737-
clone.ctx = ctx
738-
return &clone
739-
}
740-
741726
// Options returns read-only Options that were used to create the client.
742727
func (c *ClusterClient) Options() *ClusterOptions {
743728
return c.opt
@@ -1069,15 +1054,14 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
10691054
for _, node := range nodes {
10701055
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
10711056
if err != nil {
1072-
internal.Logger.Printf(c.Context(), "ReapStaleConns failed: %s", err)
1057+
internal.Logger.Printf(context.TODO(), "ReapStaleConns failed: %s", err)
10731058
}
10741059
}
10751060
}
10761061
}
10771062

10781063
func (c *ClusterClient) Pipeline() Pipeliner {
10791064
pipe := Pipeline{
1080-
ctx: c.ctx,
10811065
exec: c.processPipeline,
10821066
}
10831067
pipe.init()
@@ -1259,7 +1243,6 @@ func (c *ClusterClient) checkMovedErr(
12591243
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
12601244
func (c *ClusterClient) TxPipeline() Pipeliner {
12611245
pipe := Pipeline{
1262-
ctx: c.ctx,
12631246
exec: c.processTxPipeline,
12641247
}
12651248
pipe.init()
@@ -1616,7 +1599,7 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
16161599

16171600
info := cmdsInfo[name]
16181601
if info == nil {
1619-
internal.Logger.Printf(c.Context(), "info for cmd=%s not found", name)
1602+
internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name)
16201603
}
16211604
return info
16221605
}

cluster_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,6 @@ var _ = Describe("ClusterClient", func() {
237237
var client *redis.ClusterClient
238238

239239
assertClusterClient := func() {
240-
It("supports WithContext", func() {
241-
ctx, cancel := context.WithCancel(ctx)
242-
cancel()
243-
244-
err := client.Ping(ctx).Err()
245-
Expect(err).To(MatchError("context canceled"))
246-
})
247-
248240
It("should GET/SET/DEL", func() {
249241
err := client.Get(ctx, "A").Err()
250242
Expect(err).To(Equal(redis.Nil))

pipeline.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Pipeline struct {
3838
cmdable
3939
statefulCmdable
4040

41-
ctx context.Context
4241
exec pipelineExecer
4342

4443
mu sync.Mutex

race_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,6 @@ var _ = Describe("races", func() {
290290
Expect(atomic.LoadUint32(&received)).To(Equal(uint32(C * N)))
291291
})
292292

293-
It("should WithContext", func() {
294-
perform(C, func(_ int) {
295-
err := client.WithContext(ctx).Ping(ctx).Err()
296-
Expect(err).NotTo(HaveOccurred())
297-
})
298-
})
299-
300293
It("should abort on context timeout", func() {
301294
opt := redisClusterOptions()
302295
client := cluster.newClusterClient(ctx, opt)

redis.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,6 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
574574
return clone
575575
}
576576

577-
func (c *Client) Context() context.Context {
578-
return c.ctx
579-
}
580-
581-
func (c *Client) WithContext(ctx context.Context) *Client {
582-
if ctx == nil {
583-
panic("nil context")
584-
}
585-
clone := c.clone()
586-
clone.ctx = ctx
587-
return clone
588-
}
589-
590577
func (c *Client) Conn(ctx context.Context) *Conn {
591578
return newConn(ctx, c.opt, pool.NewStickyConnPool(c.connPool))
592579
}
@@ -629,7 +616,6 @@ func (c *Client) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
629616

630617
func (c *Client) Pipeline() Pipeliner {
631618
pipe := Pipeline{
632-
ctx: c.ctx,
633619
exec: c.processPipeline,
634620
}
635621
pipe.init()
@@ -643,7 +629,6 @@ func (c *Client) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]C
643629
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
644630
func (c *Client) TxPipeline() Pipeliner {
645631
pipe := Pipeline{
646-
ctx: c.ctx,
647632
exec: c.processTxPipeline,
648633
}
649634
pipe.init()
@@ -757,7 +742,6 @@ func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
757742

758743
func (c *Conn) Pipeline() Pipeliner {
759744
pipe := Pipeline{
760-
ctx: c.ctx,
761745
exec: c.processPipeline,
762746
}
763747
pipe.init()
@@ -771,7 +755,6 @@ func (c *Conn) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
771755
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
772756
func (c *Conn) TxPipeline() Pipeliner {
773757
pipe := Pipeline{
774-
ctx: c.ctx,
775758
exec: c.processTxPipeline,
776759
}
777760
pipe.init()

ring.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -432,21 +432,6 @@ func NewRing(opt *RingOptions) *Ring {
432432
return &ring
433433
}
434434

435-
func (c *Ring) Context() context.Context {
436-
return c.ctx
437-
}
438-
439-
func (c *Ring) WithContext(ctx context.Context) *Ring {
440-
if ctx == nil {
441-
panic("nil context")
442-
}
443-
clone := *c
444-
clone.cmdable = clone.Process
445-
clone.hooks.lock()
446-
clone.ctx = ctx
447-
return &clone
448-
}
449-
450435
// Do creates a Cmd from the args and processes the cmd.
451436
func (c *Ring) Do(ctx context.Context, args ...interface{}) *Cmd {
452437
cmd := NewCmd(ctx, args...)
@@ -619,7 +604,6 @@ func (c *Ring) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
619604

620605
func (c *Ring) Pipeline() Pipeliner {
621606
pipe := Pipeline{
622-
ctx: c.ctx,
623607
exec: c.processPipeline,
624608
}
625609
pipe.init()
@@ -638,7 +622,6 @@ func (c *Ring) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmd
638622

639623
func (c *Ring) TxPipeline() Pipeliner {
640624
pipe := Pipeline{
641-
ctx: c.ctx,
642625
exec: c.processTxPipeline,
643626
}
644627
pipe.init()

sentinel.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ func masterReplicaDialer(
256256
type SentinelClient struct {
257257
*baseClient
258258
hooks
259-
ctx context.Context
260259
}
261260

262261
func NewSentinelClient(opt *Options) *SentinelClient {
@@ -266,24 +265,10 @@ func NewSentinelClient(opt *Options) *SentinelClient {
266265
opt: opt,
267266
connPool: newConnPool(opt),
268267
},
269-
ctx: context.Background(),
270268
}
271269
return c
272270
}
273271

274-
func (c *SentinelClient) Context() context.Context {
275-
return c.ctx
276-
}
277-
278-
func (c *SentinelClient) WithContext(ctx context.Context) *SentinelClient {
279-
if ctx == nil {
280-
panic("nil context")
281-
}
282-
clone := *c
283-
clone.ctx = ctx
284-
return &clone
285-
}
286-
287272
func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error {
288273
return c.hooks.process(ctx, cmd, c.baseClient.process)
289274
}

tx.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ func (c *Tx) init() {
4141
c.statefulCmdable = c.Process
4242
}
4343

44-
func (c *Tx) Context() context.Context {
45-
return c.ctx
46-
}
47-
48-
func (c *Tx) WithContext(ctx context.Context) *Tx {
49-
if ctx == nil {
50-
panic("nil context")
51-
}
52-
clone := *c
53-
clone.init()
54-
clone.hooks.lock()
55-
clone.ctx = ctx
56-
return &clone
57-
}
58-
5944
func (c *Tx) Process(ctx context.Context, cmd Cmder) error {
6045
return c.hooks.process(ctx, cmd, c.baseClient.process)
6146
}
@@ -109,7 +94,6 @@ func (c *Tx) Unwatch(ctx context.Context, keys ...string) *StatusCmd {
10994
// Pipeline creates a pipeline. Usually it is more convenient to use Pipelined.
11095
func (c *Tx) Pipeline() Pipeliner {
11196
pipe := Pipeline{
112-
ctx: c.ctx,
11397
exec: func(ctx context.Context, cmds []Cmder) error {
11498
return c.hooks.processPipeline(ctx, cmds, c.baseClient.processPipeline)
11599
},
@@ -139,7 +123,6 @@ func (c *Tx) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder
139123
// TxPipeline creates a pipeline. Usually it is more convenient to use TxPipelined.
140124
func (c *Tx) TxPipeline() Pipeliner {
141125
pipe := Pipeline{
142-
ctx: c.ctx,
143126
exec: func(ctx context.Context, cmds []Cmder) error {
144127
return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline)
145128
},

universal.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func (o *UniversalOptions) Simple() *Options {
182182
// clients in different environments.
183183
type UniversalClient interface {
184184
Cmdable
185-
Context() context.Context
186185
AddHook(Hook)
187186
Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error
188187
Do(ctx context.Context, args ...interface{}) *Cmd

0 commit comments

Comments
 (0)