@@ -1180,8 +1180,8 @@ func (c *ClusterClient) processPipeline(ctx context.Context, cmds []Cmder) error
11801180
11811181func (c * ClusterClient ) _processPipeline (ctx context.Context , cmds []Cmder ) error {
11821182 cmdsMap := newCmdsMap ()
1183- err := c . mapCmdsByNode ( ctx , cmdsMap , cmds )
1184- if err != nil {
1183+
1184+ if err := c . mapCmdsByNode ( ctx , cmdsMap , cmds ); err != nil {
11851185 setCmdsErr (cmds , err )
11861186 return err
11871187 }
@@ -1201,18 +1201,7 @@ func (c *ClusterClient) _processPipeline(ctx context.Context, cmds []Cmder) erro
12011201 wg .Add (1 )
12021202 go func (node * clusterNode , cmds []Cmder ) {
12031203 defer wg .Done ()
1204-
1205- err := c ._processPipelineNode (ctx , node , cmds , failedCmds )
1206- if err == nil {
1207- return
1208- }
1209- if attempt < c .opt .MaxRedirects {
1210- if err := c .mapCmdsByNode (ctx , failedCmds , cmds ); err != nil {
1211- setCmdsErr (cmds , err )
1212- }
1213- } else {
1214- setCmdsErr (cmds , err )
1215- }
1204+ c ._processPipelineNode (ctx , node , cmds , failedCmds )
12161205 }(node , cmds )
12171206 }
12181207
@@ -1267,13 +1256,13 @@ func (c *ClusterClient) cmdsAreReadOnly(ctx context.Context, cmds []Cmder) bool
12671256
12681257func (c * ClusterClient ) _processPipelineNode (
12691258 ctx context.Context , node * clusterNode , cmds []Cmder , failedCmds * cmdsMap ,
1270- ) error {
1271- return node .Client .hooks .processPipeline (ctx , cmds , func (ctx context.Context , cmds []Cmder ) error {
1259+ ) {
1260+ _ = node .Client .hooks .processPipeline (ctx , cmds , func (ctx context.Context , cmds []Cmder ) error {
12721261 return node .Client .withConn (ctx , func (ctx context.Context , cn * pool.Conn ) error {
1273- err := cn .WithWriter (ctx , c .opt .WriteTimeout , func (wr * proto.Writer ) error {
1262+ if err := cn .WithWriter (ctx , c .opt .WriteTimeout , func (wr * proto.Writer ) error {
12741263 return writeCmds (wr , cmds )
1275- })
1276- if err != nil {
1264+ }); err != nil {
1265+ setCmdsErr ( cmds , err )
12771266 return err
12781267 }
12791268
@@ -1291,7 +1280,7 @@ func (c *ClusterClient) pipelineReadCmds(
12911280 cmds []Cmder ,
12921281 failedCmds * cmdsMap ,
12931282) error {
1294- for _ , cmd := range cmds {
1283+ for i , cmd := range cmds {
12951284 err := cmd .readReply (rd )
12961285 cmd .SetErr (err )
12971286
@@ -1303,15 +1292,24 @@ func (c *ClusterClient) pipelineReadCmds(
13031292 continue
13041293 }
13051294
1306- if c .opt .ReadOnly && ( isLoadingError ( err ) || ! isRedisError ( err )) {
1295+ if c .opt .ReadOnly {
13071296 node .MarkAsFailing ()
1308- return err
13091297 }
1310- if isRedisError (err ) {
1311- continue
1298+
1299+ if ! isRedisError (err ) {
1300+ if shouldRetry (err , true ) {
1301+ _ = c .mapCmdsByNode (ctx , failedCmds , cmds )
1302+ }
1303+ setCmdsErr (cmds [i + 1 :], err )
1304+ return err
13121305 }
1306+ }
1307+
1308+ if err := cmds [0 ].Err (); err != nil && shouldRetry (err , true ) {
1309+ _ = c .mapCmdsByNode (ctx , failedCmds , cmds )
13131310 return err
13141311 }
1312+
13151313 return nil
13161314}
13171315
@@ -1393,19 +1391,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er
13931391 wg .Add (1 )
13941392 go func (node * clusterNode , cmds []Cmder ) {
13951393 defer wg .Done ()
1396-
1397- err := c ._processTxPipelineNode (ctx , node , cmds , failedCmds )
1398- if err == nil {
1399- return
1400- }
1401-
1402- if attempt < c .opt .MaxRedirects {
1403- if err := c .mapCmdsByNode (ctx , failedCmds , cmds ); err != nil {
1404- setCmdsErr (cmds , err )
1405- }
1406- } else {
1407- setCmdsErr (cmds , err )
1408- }
1394+ c ._processTxPipelineNode (ctx , node , cmds , failedCmds )
14091395 }(node , cmds )
14101396 }
14111397
@@ -1431,34 +1417,39 @@ func (c *ClusterClient) mapCmdsBySlot(ctx context.Context, cmds []Cmder) map[int
14311417
14321418func (c * ClusterClient ) _processTxPipelineNode (
14331419 ctx context.Context , node * clusterNode , cmds []Cmder , failedCmds * cmdsMap ,
1434- ) error {
1435- return node .Client .hooks .processTxPipeline (ctx , cmds , func (ctx context.Context , cmds []Cmder ) error {
1436- return node .Client .withConn (ctx , func (ctx context.Context , cn * pool.Conn ) error {
1437- err := cn .WithWriter (ctx , c .opt .WriteTimeout , func (wr * proto.Writer ) error {
1438- return writeCmds (wr , cmds )
1439- })
1440- if err != nil {
1441- return err
1442- }
1443-
1444- return cn .WithReader (ctx , c .opt .ReadTimeout , func (rd * proto.Reader ) error {
1445- statusCmd := cmds [0 ].(* StatusCmd )
1446- // Trim multi and exec.
1447- cmds = cmds [1 : len (cmds )- 1 ]
1448-
1449- err := c .txPipelineReadQueued (ctx , rd , statusCmd , cmds , failedCmds )
1450- if err != nil {
1451- moved , ask , addr := isMovedError (err )
1452- if moved || ask {
1453- return c .cmdsMoved (ctx , cmds , moved , ask , addr , failedCmds )
1454- }
1420+ ) {
1421+ _ = node .Client .hooks .processTxPipeline (
1422+ ctx , cmds , func (ctx context.Context , cmds []Cmder ) error {
1423+ return node .Client .withConn (ctx , func (ctx context.Context , cn * pool.Conn ) error {
1424+ if err := cn .WithWriter (ctx , c .opt .WriteTimeout , func (wr * proto.Writer ) error {
1425+ return writeCmds (wr , cmds )
1426+ }); err != nil {
1427+ setCmdsErr (cmds , err )
14551428 return err
14561429 }
14571430
1458- return pipelineReadCmds (rd , cmds )
1431+ return cn .WithReader (ctx , c .opt .ReadTimeout , func (rd * proto.Reader ) error {
1432+ statusCmd := cmds [0 ].(* StatusCmd )
1433+ // Trim multi and exec.
1434+ trimmedCmds := cmds [1 : len (cmds )- 1 ]
1435+
1436+ if err := c .txPipelineReadQueued (
1437+ ctx , rd , statusCmd , trimmedCmds , failedCmds ,
1438+ ); err != nil {
1439+ setCmdsErr (cmds , err )
1440+
1441+ moved , ask , addr := isMovedError (err )
1442+ if moved || ask {
1443+ return c .cmdsMoved (ctx , trimmedCmds , moved , ask , addr , failedCmds )
1444+ }
1445+
1446+ return err
1447+ }
1448+
1449+ return pipelineReadCmds (rd , trimmedCmds )
1450+ })
14591451 })
14601452 })
1461- })
14621453}
14631454
14641455func (c * ClusterClient ) txPipelineReadQueued (
0 commit comments