forked from mirror/redis
multi: Use mutex to sychronize reads and writes.
This commit is contained in:
parent
2f5c2aa6be
commit
303687e438
5
multi.go
5
multi.go
|
@ -2,10 +2,12 @@ package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MultiClient struct {
|
type MultiClient struct {
|
||||||
*Client
|
*Client
|
||||||
|
execMtx sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) MultiClient() (*MultiClient, error) {
|
func (c *Client) MultiClient() (*MultiClient, error) {
|
||||||
|
@ -64,7 +66,10 @@ func (c *MultiClient) Exec(do func()) ([]Req, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Synchronize writes and reads to the connection using mutex.
|
||||||
|
c.execMtx.Lock()
|
||||||
err = c.ExecReqs(reqs, conn)
|
err = c.ExecReqs(reqs, conn)
|
||||||
|
c.execMtx.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ConnPool.Remove(conn)
|
c.ConnPool.Remove(conn)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue