mirror of
https://github.com/redis/go-redis.git
synced 2025-07-31 05:04:23 +03:00
fix(txpipeline): should return error on multi/exec on multiple slots [CAE-1028] (#3408)
* fix(txpipeline): should return error on multi/exec on multiple slots * fix(txpipeline): test normal tx pipeline behaviour * chore(err): Extract crossslot err and add test * fix(txpipeline): short curcuit the tx if there are no commands * chore(tests): validate keys are in different slots
This commit is contained in:
@ -1497,6 +1497,10 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err
|
||||
// Trim multi .. exec.
|
||||
cmds = cmds[1 : len(cmds)-1]
|
||||
|
||||
if len(cmds) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
state, err := c.state.Get(ctx)
|
||||
if err != nil {
|
||||
setCmdsErr(cmds, err)
|
||||
@ -1504,6 +1508,12 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err
|
||||
}
|
||||
|
||||
cmdsMap := c.mapCmdsBySlot(cmds)
|
||||
// TxPipeline does not support cross slot transaction.
|
||||
if len(cmdsMap) > 1 {
|
||||
setCmdsErr(cmds, ErrCrossSlot)
|
||||
return ErrCrossSlot
|
||||
}
|
||||
|
||||
for slot, cmds := range cmdsMap {
|
||||
node, err := state.slotMasterNode(slot)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user