From 9d06871d6e458d765a3012fd5d241d50d97aec8f Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 29 Jul 2012 12:51:29 +0300 Subject: [PATCH] Fix waiting reply on empty queue. --- redis.go | 8 ++++++++ redis_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/redis.go b/redis.go index 2237468..c2aa948 100644 --- a/redis.go +++ b/redis.go @@ -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) diff --git a/redis_test.go b/redis_test.go index 14db776..b216974 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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) {