multi: Properly reset client in case of empty transaction.

This commit is contained in:
Vladimir Mihailenco 2012-08-25 21:54:35 +03:00
parent 4e3743c0d6
commit ee844aaf1d
2 changed files with 21 additions and 3 deletions

View File

@ -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()

View File

@ -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)