From b11853c05013a6e635fb4903382e1f85576d9195 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 2 Jul 2014 16:18:19 +0300 Subject: [PATCH] Allow Pipelined funcs to return error. --- multi.go | 6 ++++-- pipeline.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/multi.go b/multi.go index e75fbc8a..bff38dfa 100644 --- a/multi.go +++ b/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 diff --git a/pipeline.go b/pipeline.go index 6d436d2d..1f51da45 100644 --- a/pipeline.go +++ b/pipeline.go @@ -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