From 037888ee0f26f327b4079b8a01476006e55b67a1 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 25 Aug 2012 22:51:42 +0300 Subject: [PATCH] multi: Restrict Discard usage. --- multi.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/multi.go b/multi.go index cece9ec..061a1ec 100644 --- a/multi.go +++ b/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()