Fix waiting reply on empty queue.

This commit is contained in:
Vladimir Mihailenco 2012-07-29 12:51:29 +03:00
parent 41137c2e6f
commit 9d06871d6e
2 changed files with 20 additions and 0 deletions

View File

@ -131,6 +131,10 @@ func (c *Client) Run(req Req) {
}
func (c *Client) RunQueued() ([]Req, error) {
if len(c.reqs) == 0 {
return c.reqs, nil
}
c.mtx.Lock()
reqs := c.reqs
c.reqs = make([]Req, 0)
@ -177,6 +181,10 @@ func (c *Client) Discard() {
}
func (c *Client) Exec() ([]Req, error) {
if len(c.reqs) == 0 {
return c.reqs, nil
}
c.mtx.Lock()
reqs := c.reqs
c.reqs = make([]Req, 0)

View File

@ -1372,6 +1372,12 @@ func (t *RedisTest) TestPipelining(c *C) {
c.Check(v, Equals, "bar2")
}
func (t *RedisTest) TestRunQueuedOnEmptyQueue(c *C) {
reqs, err := t.redisC.RunQueued()
c.Check(err, IsNil)
c.Check(reqs, HasLen, 0)
}
//------------------------------------------------------------------------------
func (t *RedisTest) TestDiscard(c *C) {
@ -1412,6 +1418,12 @@ func (t *RedisTest) TestMultiExec(c *C) {
c.Check(v, Equals, "bar")
}
func (t *RedisTest) TestExecOnEmptyQueue(c *C) {
reqs, err := t.redisC.Exec()
c.Check(err, IsNil)
c.Check(reqs, HasLen, 0)
}
//------------------------------------------------------------------------------
func (t *RedisTest) TestConcAccess(c *C) {