pipeline: Add DiscardQueued method.

This commit is contained in:
Vladimir Mihailenco 2012-08-19 23:19:00 +03:00
parent 569b1b07ac
commit a654224ced
2 changed files with 20 additions and 0 deletions

View File

@ -30,6 +30,12 @@ func (c *PipelineClient) Close() error {
return nil return nil
} }
func (c *PipelineClient) DiscardQueued() {
c.mtx.Lock()
c.reqs = c.reqs[:0]
c.mtx.Unlock()
}
func (c *PipelineClient) RunQueued() ([]Req, error) { func (c *PipelineClient) RunQueued() ([]Req, error) {
c.mtx.Lock() c.mtx.Lock()
if len(c.reqs) == 0 { if len(c.reqs) == 0 {

View File

@ -2184,6 +2184,20 @@ func (t *RedisTest) TestPipeline(c *C) {
c.Assert(getNil.Val(), Equals, "") c.Assert(getNil.Val(), Equals, "")
} }
func (t *RedisTest) TestPipelineDiscardQueued(c *C) {
pipeline, err := t.client.PipelineClient()
c.Assert(err, IsNil)
defer func() {
c.Assert(pipeline.Close(), IsNil)
}()
pipeline.Get("key")
pipeline.DiscardQueued()
reqs, err := pipeline.RunQueued()
c.Assert(err, IsNil)
c.Assert(reqs, HasLen, 0)
}
func (t *RedisTest) TestPipelineFunc(c *C) { func (t *RedisTest) TestPipelineFunc(c *C) {
var get *redis.StringReq var get *redis.StringReq
reqs, err := t.client.Pipelined(func(c *redis.PipelineClient) { reqs, err := t.client.Pipelined(func(c *redis.PipelineClient) {