forked from mirror/redis
multi: Properly reset client in case of empty transaction.
This commit is contained in:
parent
4e3743c0d6
commit
ee844aaf1d
8
multi.go
8
multi.go
|
@ -53,12 +53,14 @@ func (c *MultiClient) Exec(do func()) ([]Req, error) {
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
c.reqs = append(c.reqs, NewIfaceSliceReq("EXEC"))
|
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()
|
c.mtx.Unlock()
|
||||||
return []Req{}, nil
|
return []Req{}, nil
|
||||||
}
|
}
|
||||||
reqs := c.reqs
|
|
||||||
c.reqs = nil
|
|
||||||
c.mtx.Unlock()
|
c.mtx.Unlock()
|
||||||
|
|
||||||
conn, err := c.conn()
|
conn, err := c.conn()
|
||||||
|
|
|
@ -2395,6 +2395,22 @@ func (t *RedisTest) TestMultiExecDiscard(c *C) {
|
||||||
c.Assert(get.Val(), Equals, "hello2")
|
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) {
|
func (t *RedisTest) TestMultiExecOnEmptyQueue(c *C) {
|
||||||
multi, err := t.client.MultiClient()
|
multi, err := t.client.MultiClient()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
Loading…
Reference in New Issue