Skip to content

Commit e061db8

Browse files
authored
refactor: remove unused context attributes (#2154)
* refactor: remove unused context field
1 parent 092a692 commit e061db8

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

cluster.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ type ClusterClient struct {
708708
*clusterClient
709709
cmdable
710710
hooks
711-
ctx context.Context
712711
}
713712

714713
// NewClusterClient returns a Redis Cluster client as described in
@@ -721,7 +720,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
721720
opt: opt,
722721
nodes: newClusterNodes(opt),
723722
},
724-
ctx: context.Background(),
725723
}
726724
c.state = newClusterStateHolder(c.loadState)
727725
c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
@@ -765,8 +763,8 @@ func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error {
765763
}
766764

767765
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
768-
cmdInfo := c.cmdInfo(cmd.Name())
769-
slot := c.cmdSlot(cmd)
766+
cmdInfo := c.cmdInfo(ctx, cmd.Name())
767+
slot := c.cmdSlot(ctx, cmd)
770768

771769
var node *clusterNode
772770
var ask bool
@@ -1141,9 +1139,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11411139
return err
11421140
}
11431141

1144-
if c.opt.ReadOnly && c.cmdsAreReadOnly(cmds) {
1142+
if c.opt.ReadOnly && c.cmdsAreReadOnly(ctx, cmds) {
11451143
for _, cmd := range cmds {
1146-
slot := c.cmdSlot(cmd)
1144+
slot := c.cmdSlot(ctx, cmd)
11471145
node, err := c.slotReadOnlyNode(state, slot)
11481146
if err != nil {
11491147
return err
@@ -1154,7 +1152,7 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11541152
}
11551153

11561154
for _, cmd := range cmds {
1157-
slot := c.cmdSlot(cmd)
1155+
slot := c.cmdSlot(ctx, cmd)
11581156
node, err := state.slotMasterNode(slot)
11591157
if err != nil {
11601158
return err
@@ -1164,9 +1162,9 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd
11641162
return nil
11651163
}
11661164

1167-
func (c *ClusterClient) cmdsAreReadOnly(cmds []Cmder) bool {
1165+
func (c *ClusterClient) cmdsAreReadOnly(ctx context.Context, cmds []Cmder) bool {
11681166
for _, cmd := range cmds {
1169-
cmdInfo := c.cmdInfo(cmd.Name())
1167+
cmdInfo := c.cmdInfo(ctx, cmd.Name())
11701168
if cmdInfo == nil || !cmdInfo.ReadOnly {
11711169
return false
11721170
}
@@ -1278,7 +1276,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
12781276
return err
12791277
}
12801278

1281-
cmdsMap := c.mapCmdsBySlot(cmds)
1279+
cmdsMap := c.mapCmdsBySlot(ctx, cmds)
12821280
for slot, cmds := range cmdsMap {
12831281
node, err := state.slotMasterNode(slot)
12841282
if err != nil {
@@ -1329,10 +1327,10 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
13291327
return cmdsFirstErr(cmds)
13301328
}
13311329

1332-
func (c *ClusterClient) mapCmdsBySlot(cmds []Cmder) map[int][]Cmder {
1330+
func (c *ClusterClient) mapCmdsBySlot(ctx context.Context, cmds []Cmder) map[int][]Cmder {
13331331
cmdsMap := make(map[int][]Cmder)
13341332
for _, cmd := range cmds {
1335-
slot := c.cmdSlot(cmd)
1333+
slot := c.cmdSlot(ctx, cmd)
13361334
cmdsMap[slot] = append(cmdsMap[slot], cmd)
13371335
}
13381336
return cmdsMap
@@ -1602,8 +1600,8 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo,
16021600
return nil, firstErr
16031601
}
16041602

1605-
func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
1606-
cmdsInfo, err := c.cmdsInfoCache.Get(c.ctx)
1603+
func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
1604+
cmdsInfo, err := c.cmdsInfoCache.Get(ctx)
16071605
if err != nil {
16081606
internal.Logger.Printf(context.TODO(), "getting command info: %s", err)
16091607
return nil
@@ -1616,13 +1614,13 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
16161614
return info
16171615
}
16181616

1619-
func (c *ClusterClient) cmdSlot(cmd Cmder) int {
1617+
func (c *ClusterClient) cmdSlot(ctx context.Context, cmd Cmder) int {
16201618
args := cmd.Args()
16211619
if args[0] == "cluster" && args[1] == "getkeysinslot" {
16221620
return args[2].(int)
16231621
}
16241622

1625-
cmdInfo := c.cmdInfo(cmd.Name())
1623+
cmdInfo := c.cmdInfo(ctx, cmd.Name())
16261624
return cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo))
16271625
}
16281626

redis.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ type Client struct {
546546
*baseClient
547547
cmdable
548548
hooks
549-
ctx context.Context
550549
}
551550

552551
// NewClient returns a client to the Redis Server specified by Options.
@@ -555,7 +554,6 @@ func NewClient(opt *Options) *Client {
555554

556555
c := Client{
557556
baseClient: newBaseClient(opt, newConnPool(opt)),
558-
ctx: context.Background(),
559557
}
560558
c.cmdable = c.Process
561559

ring.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ type Ring struct {
410410
*ring
411411
cmdable
412412
hooks
413-
ctx context.Context
414413
}
415414

416415
func NewRing(opt *RingOptions) *Ring {
@@ -421,7 +420,6 @@ func NewRing(opt *RingOptions) *Ring {
421420
opt: opt,
422421
shards: newRingShards(opt),
423422
},
424-
ctx: context.Background(),
425423
}
426424

427425
ring.cmdsInfoCache = newCmdsInfoCache(ring.cmdsInfo)

sentinel.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
209209

210210
c := Client{
211211
baseClient: newBaseClient(opt, connPool),
212-
ctx: context.Background(),
213212
}
214213
c.cmdable = c.Process
215214
c.onClose = failover.Close

tx.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ type Tx struct {
2020
cmdable
2121
statefulCmdable
2222
hooks
23-
ctx context.Context
2423
}
2524

26-
func (c *Client) newTx(ctx context.Context) *Tx {
25+
func (c *Client) newTx() *Tx {
2726
tx := Tx{
2827
baseClient: baseClient{
2928
opt: c.opt,
3029
connPool: pool.NewStickyConnPool(c.connPool),
3130
},
3231
hooks: c.hooks.clone(),
33-
ctx: ctx,
3432
}
3533
tx.init()
3634
return &tx
@@ -50,7 +48,7 @@ func (c *Tx) Process(ctx context.Context, cmd Cmder) error {
5048
//
5149
// The transaction is automatically closed when fn exits.
5250
func (c *Client) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error {
53-
tx := c.newTx(ctx)
51+
tx := c.newTx()
5452
defer tx.Close(ctx)
5553
if len(keys) > 0 {
5654
if err := tx.Watch(ctx, keys...).Err(); err != nil {

0 commit comments

Comments
 (0)