mirror of https://github.com/go-redis/redis.git
Allow Pipelined funcs to return error.
This commit is contained in:
parent
4ea3e7531b
commit
b11853c050
6
multi.go
6
multi.go
|
@ -55,9 +55,11 @@ func (c *Multi) Discard() error {
|
|||
// Exec always returns list of commands. If transaction fails
|
||||
// TxFailedErr is returned. Otherwise Exec returns error of the first
|
||||
// failed command or nil.
|
||||
func (c *Multi) Exec(f func()) ([]Cmder, error) {
|
||||
func (c *Multi) Exec(f func() error) ([]Cmder, error) {
|
||||
c.cmds = []Cmder{NewStatusCmd("MULTI")}
|
||||
f()
|
||||
if err := f(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.cmds = append(c.cmds, NewSliceCmd("EXEC"))
|
||||
|
||||
cmds := c.cmds
|
||||
|
|
|
@ -20,9 +20,11 @@ func (c *Client) Pipeline() *Pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Client) Pipelined(f func(*Pipeline)) ([]Cmder, error) {
|
||||
func (c *Client) Pipelined(f func(*Pipeline) error) ([]Cmder, error) {
|
||||
pc := c.Pipeline()
|
||||
f(pc)
|
||||
if err := f(pc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmds, err := pc.Exec()
|
||||
pc.Close()
|
||||
return cmds, err
|
||||
|
|
Loading…
Reference in New Issue