diff --git a/multi.go b/multi.go index 8a87528..091989e 100644 --- a/multi.go +++ b/multi.go @@ -53,12 +53,14 @@ func (c *MultiClient) Exec(do func()) ([]Req, error) { c.mtx.Lock() c.reqs = append(c.reqs, NewIfaceSliceReq("EXEC")) - if len(c.reqs) == 2 { + + reqs := c.reqs + c.reqs = nil + + if len(reqs) == 2 { c.mtx.Unlock() return []Req{}, nil } - reqs := c.reqs - c.reqs = nil c.mtx.Unlock() conn, err := c.conn() diff --git a/redis_test.go b/redis_test.go index 048adfd..682b872 100644 --- a/redis_test.go +++ b/redis_test.go @@ -2395,6 +2395,22 @@ func (t *RedisTest) TestMultiExecDiscard(c *C) { c.Assert(get.Val(), Equals, "hello2") } +func (t *RedisTest) TestMultiExecEmpty(c *C) { + multi, err := t.client.MultiClient() + c.Assert(err, IsNil) + defer func() { + c.Assert(multi.Close(), IsNil) + }() + + reqs, err := multi.Exec(func() {}) + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 0) + + ping := multi.Ping() + c.Check(ping.Err(), IsNil) + c.Check(ping.Val(), Equals, "PONG") +} + func (t *RedisTest) TestMultiExecOnEmptyQueue(c *C) { multi, err := t.client.MultiClient() c.Assert(err, IsNil)