mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Reuse single Pipeline type in Client, ClusterClient and Ring.
This commit is contained in:
37
redis.go
37
redis.go
@ -174,3 +174,40 @@ func (c *Client) PoolStats() *PoolStats {
|
||||
FreeConns: s.FreeConns,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Pipeline() *Pipeline {
|
||||
pipe := &Pipeline{
|
||||
exec: c.pipelineExec,
|
||||
}
|
||||
pipe.commandable.process = pipe.process
|
||||
return pipe
|
||||
}
|
||||
|
||||
func (c *Client) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) {
|
||||
return c.Pipeline().pipelined(fn)
|
||||
}
|
||||
|
||||
func (c *Client) pipelineExec(cmds []Cmder) error {
|
||||
var retErr error
|
||||
failedCmds := cmds
|
||||
for i := 0; i <= c.opt.MaxRetries; i++ {
|
||||
cn, err := c.conn()
|
||||
if err != nil {
|
||||
setCmdsErr(failedCmds, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if i > 0 {
|
||||
resetCmds(failedCmds)
|
||||
}
|
||||
failedCmds, err = execCmds(cn, failedCmds)
|
||||
c.putConn(cn, err, false)
|
||||
if err != nil && retErr == nil {
|
||||
retErr = err
|
||||
}
|
||||
if len(failedCmds) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return retErr
|
||||
}
|
||||
|
Reference in New Issue
Block a user