1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

fix(txpipeline): extract only keyed cmds from all cmds

This commit is contained in:
Nedyalko Dyakov
2025-06-19 11:52:09 +03:00
parent fd2f7044cb
commit fffa489c04

View File

@ -1521,8 +1521,8 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err
cmdsMap := map[int][]Cmder{} cmdsMap := map[int][]Cmder{}
slot := -1 slot := -1
// split keyed and keyless commands // get only the keyed commands
keyedCmds, _ := c.keyedAndKeyessCmds(cmds) keyedCmds := c.keyedCmds(cmds)
if len(keyedCmds) == 0 { if len(keyedCmds) == 0 {
// no keyed commands try random slot // no keyed commands try random slot
slot = hashtag.RandomSlot() slot = hashtag.RandomSlot()
@ -1600,17 +1600,17 @@ func (c *ClusterClient) mapCmdsBySlot(cmds []Cmder) map[int][]Cmder {
} }
return cmdsMap return cmdsMap
} }
func (c *ClusterClient) keyedAndKeyessCmds(cmds []Cmder) ([]Cmder, []Cmder) {
// keyedCmds returns all the keyed commands from the cmds slice
// it determines keyed commands by checking if the command has a first key position
func (c *ClusterClient) keyedCmds(cmds []Cmder) []Cmder {
keyedCmds := make([]Cmder, 0, len(cmds)) keyedCmds := make([]Cmder, 0, len(cmds))
keylessCmds := make([]Cmder, 0, len(cmds))
for _, cmd := range cmds { for _, cmd := range cmds {
if cmdFirstKeyPos(cmd) == 0 { if cmdFirstKeyPos(cmd) != 0 {
keylessCmds = append(keylessCmds, cmd)
} else {
keyedCmds = append(keyedCmds, cmd) keyedCmds = append(keyedCmds, cmd)
} }
} }
return keyedCmds, keylessCmds return keyedCmds
} }
func (c *ClusterClient) processTxPipelineNode( func (c *ClusterClient) processTxPipelineNode(