1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Fix WithContext and add tests

This commit is contained in:
Vladimir Mihailenco
2019-07-04 11:18:06 +03:00
parent 73d3c18522
commit 2cbb5194fb
14 changed files with 114 additions and 90 deletions

View File

@ -358,6 +358,7 @@ func NewRing(opt *RingOptions) *Ring {
opt: opt,
shards: newRingShards(opt),
},
ctx: context.Background(),
}
ring.init()
@ -379,10 +380,7 @@ func (c *Ring) init() {
}
func (c *Ring) Context() context.Context {
if c.ctx != nil {
return c.ctx
}
return context.Background()
return c.ctx
}
func (c *Ring) WithContext(ctx context.Context) *Ring {
@ -391,6 +389,7 @@ func (c *Ring) WithContext(ctx context.Context) *Ring {
}
clone := *c
clone.ctx = ctx
clone.init()
return &clone
}
@ -401,7 +400,7 @@ func (c *Ring) Do(args ...interface{}) *Cmd {
func (c *Ring) DoContext(ctx context.Context, args ...interface{}) *Cmd {
cmd := NewCmd(args...)
c.ProcessContext(ctx, cmd)
_ = c.ProcessContext(ctx, cmd)
return cmd
}