mirror of https://github.com/go-redis/redis.git
pipeline: Add DiscardQueued method.
This commit is contained in:
parent
569b1b07ac
commit
a654224ced
|
@ -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 {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue