mirror of https://github.com/go-redis/redis.git
multi: Restrict Discard usage.
This commit is contained in:
parent
dbcfb0984e
commit
037888ee0f
11
multi.go
11
multi.go
|
@ -42,13 +42,20 @@ func (c *MultiClient) Unwatch(keys ...string) *StatusReq {
|
|||
|
||||
func (c *MultiClient) Discard() {
|
||||
c.reqsMtx.Lock()
|
||||
c.reqs = []Req{NewStatusReq("MULTI")}
|
||||
if c.reqs == nil {
|
||||
panic("Discard can be used only inside Exec")
|
||||
}
|
||||
c.reqs = c.reqs[:1]
|
||||
c.reqsMtx.Unlock()
|
||||
}
|
||||
|
||||
func (c *MultiClient) Exec(do func()) ([]Req, error) {
|
||||
c.Discard()
|
||||
c.reqsMtx.Lock()
|
||||
c.reqs = []Req{NewStatusReq("MULTI")}
|
||||
c.reqsMtx.Unlock()
|
||||
|
||||
do()
|
||||
|
||||
c.Queue(NewIfaceSliceReq("EXEC"))
|
||||
|
||||
c.reqsMtx.Lock()
|
||||
|
|
Loading…
Reference in New Issue