forked from mirror/redis
Fix waiting reply on empty queue.
This commit is contained in:
parent
41137c2e6f
commit
9d06871d6e
8
redis.go
8
redis.go
|
@ -131,6 +131,10 @@ func (c *Client) Run(req Req) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RunQueued() ([]Req, error) {
|
func (c *Client) RunQueued() ([]Req, error) {
|
||||||
|
if len(c.reqs) == 0 {
|
||||||
|
return c.reqs, nil
|
||||||
|
}
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
reqs := c.reqs
|
reqs := c.reqs
|
||||||
c.reqs = make([]Req, 0)
|
c.reqs = make([]Req, 0)
|
||||||
|
@ -177,6 +181,10 @@ func (c *Client) Discard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Exec() ([]Req, error) {
|
func (c *Client) Exec() ([]Req, error) {
|
||||||
|
if len(c.reqs) == 0 {
|
||||||
|
return c.reqs, nil
|
||||||
|
}
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
reqs := c.reqs
|
reqs := c.reqs
|
||||||
c.reqs = make([]Req, 0)
|
c.reqs = make([]Req, 0)
|
||||||
|
|
|
@ -1372,6 +1372,12 @@ func (t *RedisTest) TestPipelining(c *C) {
|
||||||
c.Check(v, Equals, "bar2")
|
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) {
|
func (t *RedisTest) TestDiscard(c *C) {
|
||||||
|
@ -1412,6 +1418,12 @@ func (t *RedisTest) TestMultiExec(c *C) {
|
||||||
c.Check(v, Equals, "bar")
|
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) {
|
func (t *RedisTest) TestConcAccess(c *C) {
|
||||||
|
|
Loading…
Reference in New Issue