1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

multi: Restrict Discard usage.

This commit is contained in:
Vladimir Mihailenco
2012-08-25 22:51:42 +03:00
parent dbcfb0984e
commit 037888ee0f

View File

@ -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()