Allow Pipelined funcs to return error.

This commit is contained in:
Vladimir Mihailenco 2014-07-02 16:18:19 +03:00
parent 4ea3e7531b
commit b11853c050
2 changed files with 8 additions and 4 deletions

View File

@ -55,9 +55,11 @@ func (c *Multi) Discard() error {
// Exec always returns list of commands. If transaction fails // Exec always returns list of commands. If transaction fails
// TxFailedErr is returned. Otherwise Exec returns error of the first // TxFailedErr is returned. Otherwise Exec returns error of the first
// failed command or nil. // 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")} c.cmds = []Cmder{NewStatusCmd("MULTI")}
f() if err := f(); err != nil {
return nil, err
}
c.cmds = append(c.cmds, NewSliceCmd("EXEC")) c.cmds = append(c.cmds, NewSliceCmd("EXEC"))
cmds := c.cmds cmds := c.cmds

View File

@ -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() pc := c.Pipeline()
f(pc) if err := f(pc); err != nil {
return nil, err
}
cmds, err := pc.Exec() cmds, err := pc.Exec()
pc.Close() pc.Close()
return cmds, err return cmds, err