mirror of
https://github.com/redis/go-redis.git
synced 2025-08-07 12:42:55 +03:00
Use cmdSlotAndNode() to route read-only ClusterClient pipeline commands
This commit is contained in:
21
cluster.go
21
cluster.go
@@ -1207,9 +1207,16 @@ func (c *ClusterClient) mapCmdsByNode(cmds []Cmder) (map[*clusterNode][]Cmder, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdsMap := make(map[*clusterNode][]Cmder)
|
cmdsMap := make(map[*clusterNode][]Cmder)
|
||||||
|
cmdsAreReadOnly := c.cmdsAreReadOnly(cmds)
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
slot := c.cmdSlot(cmd)
|
var node *clusterNode
|
||||||
node, err := state.slotMasterNode(slot)
|
var err error
|
||||||
|
if cmdsAreReadOnly {
|
||||||
|
_, node, err = c.cmdSlotAndNode(cmd)
|
||||||
|
} else {
|
||||||
|
slot := c.cmdSlot(cmd)
|
||||||
|
node, err = state.slotMasterNode(slot)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1218,6 +1225,16 @@ func (c *ClusterClient) mapCmdsByNode(cmds []Cmder) (map[*clusterNode][]Cmder, e
|
|||||||
return cmdsMap, nil
|
return cmdsMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClusterClient) cmdsAreReadOnly(cmds []Cmder) bool {
|
||||||
|
for _, cmd := range cmds {
|
||||||
|
cmdInfo := c.cmdInfo(cmd.Name())
|
||||||
|
if cmdInfo == nil || !cmdInfo.ReadOnly {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) remapCmds(cmds []Cmder, failedCmds map[*clusterNode][]Cmder) {
|
func (c *ClusterClient) remapCmds(cmds []Cmder, failedCmds map[*clusterNode][]Cmder) {
|
||||||
remappedCmds, err := c.mapCmdsByNode(cmds)
|
remappedCmds, err := c.mapCmdsByNode(cmds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user