multi: Use mutex to sychronize reads and writes.

This commit is contained in:
Vladimir Mihailenco 2012-08-20 12:10:00 +03:00
parent 2f5c2aa6be
commit 303687e438
1 changed files with 5 additions and 0 deletions

View File

@ -2,10 +2,12 @@ package redis
import (
"fmt"
"sync"
)
type MultiClient struct {
*Client
execMtx sync.Mutex
}
func (c *Client) MultiClient() (*MultiClient, error) {
@ -64,7 +66,10 @@ func (c *MultiClient) Exec(do func()) ([]Req, error) {
return nil, err
}
// Synchronize writes and reads to the connection using mutex.
c.execMtx.Lock()
err = c.ExecReqs(reqs, conn)
c.execMtx.Unlock()
if err != nil {
c.ConnPool.Remove(conn)
return nil, err