Skip to content

Commit

Permalink
refactor: remove last slot too
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Dec 13, 2024
1 parent 78cddd8 commit 87040ac
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ func (c *clusterClient) toReplica(cmd Completed) bool {
return false
}

func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last uint16) {
last = cmds.InitSlot
func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry) {
last := cmds.InitSlot
init := false

for _, cmd := range multi {
Expand All @@ -526,7 +526,7 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last
p = c.pslots[cmd.Slot()]
}
if p == nil {
return nil, 0
return nil
}
count.m[p]++
}
Expand All @@ -551,7 +551,7 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last
re.commands = append(re.commands, cmd)
re.cIndexes = append(re.cIndexes, i)
}
return retries, last
return retries
}

inits := 0
Expand All @@ -567,7 +567,7 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last
}
p := c.pslots[cmd.Slot()]
if p == nil {
return nil, 0
return nil
}
count.m[p]++
}
Expand All @@ -582,7 +582,7 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last
}
}
if last == cmds.InitSlot {
return nil, 0
return nil
}
}

Expand All @@ -603,20 +603,20 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, last
re.commands = append(re.commands, cmd)
re.cIndexes = append(re.cIndexes, i)
}
return retries, last
return retries
}

func (c *clusterClient) pickMulti(ctx context.Context, multi []Completed) (*connretry, uint16, error) {
conns, slot := c._pickMulti(multi)
func (c *clusterClient) pickMulti(ctx context.Context, multi []Completed) (*connretry, error) {
conns := c._pickMulti(multi)
if conns == nil {
if err := c.refresh(ctx); err != nil {
return nil, 0, err
return nil, err
}
if conns, slot = c._pickMulti(multi); conns == nil {
return nil, 0, ErrNoSlot
if conns = c._pickMulti(multi); conns == nil {
return nil, ErrNoSlot
}
}
return conns, slot, nil
return conns, nil
}

func (c *clusterClient) doresultfn(
Expand Down Expand Up @@ -687,7 +687,7 @@ func (c *clusterClient) DoMulti(ctx context.Context, multi ...Completed) []Redis
return nil
}

retries, _, err := c.pickMulti(ctx, multi)
retries, err := c.pickMulti(ctx, multi)
if err != nil {
return fillErrs(len(multi), err)
}
Expand Down

0 comments on commit 87040ac

Please sign in to comment.