From fffa489c049ab17db11bcacf4b0e74142b32a282 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Thu, 19 Jun 2025 11:52:09 +0300 Subject: [PATCH] fix(txpipeline): extract only keyed cmds from all cmds --- osscluster.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osscluster.go b/osscluster.go index b3665cc2..48630929 100644 --- a/osscluster.go +++ b/osscluster.go @@ -1521,8 +1521,8 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err cmdsMap := map[int][]Cmder{} slot := -1 - // split keyed and keyless commands - keyedCmds, _ := c.keyedAndKeyessCmds(cmds) + // get only the keyed commands + keyedCmds := c.keyedCmds(cmds) if len(keyedCmds) == 0 { // no keyed commands try random slot slot = hashtag.RandomSlot() @@ -1600,17 +1600,17 @@ func (c *ClusterClient) mapCmdsBySlot(cmds []Cmder) map[int][]Cmder { } 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)) - keylessCmds := make([]Cmder, 0, len(cmds)) for _, cmd := range cmds { - if cmdFirstKeyPos(cmd) == 0 { - keylessCmds = append(keylessCmds, cmd) - } else { + if cmdFirstKeyPos(cmd) != 0 { keyedCmds = append(keyedCmds, cmd) } } - return keyedCmds, keylessCmds + return keyedCmds } func (c *ClusterClient) processTxPipelineNode(