Skip to content

Commit

Permalink
Merge pull request #28 from jumpeiMano/feature/lock
Browse files Browse the repository at this point in the history
Get lock of conn and fix typo
  • Loading branch information
jumpeiMano authored Apr 17, 2019
2 parents 973d757 + bc93da8 commit 44e1861
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
### SetConnMaxOpen
SetConnMaxOpen sets the maximum amount of opening connections. Default is 0 (unlimited).

### SetConnectTimeout
### SetConnMaxLifetime
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
Expired connections may be closed lazily before reuse. If d <= 0, connections are reused forever.
Default is 0.
Expand Down
8 changes: 7 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ func (cl *Client) Delete(noreply bool, keys ...string) (failedKeys []string, err
wg.Add(1)
go func(c *conn) {
defer wg.Done()
c.mu.Lock()
defer c.mu.Unlock()
if err := c.flush(); err != nil {
ec <- errors.Wrap(err, "Failed flush")
}
Expand Down Expand Up @@ -472,6 +474,8 @@ func (cl *Client) getOrGat(command string, exp int64, keys []string) ([]*Item, e
wg.Add(1)
go func(c *conn) {
defer wg.Done()
c.mu.Lock()
defer c.mu.Unlock()
if err := c.writestrings("\r\n"); err != nil {
ec <- errors.Wrap(err, "Failed writestrings")
return
Expand Down Expand Up @@ -618,7 +622,7 @@ func (cl *Client) store(command string, items []*Item, noreply bool) ([]string,
}
if item.Cas != 0 {
if err = c.writestring(" "); err != nil {
ec <- errors.Wrap(err, "Failed writestrint")
ec <- errors.Wrap(err, "Failed writestring")
return
}
if err := c.write(strconv.AppendUint(nil, item.Cas, 10)); err != nil {
Expand Down Expand Up @@ -664,6 +668,8 @@ func (cl *Client) store(command string, items []*Item, noreply bool) ([]string,
wg.Add(1)
go func(c *conn) {
defer wg.Done()
c.mu.Lock()
defer c.mu.Unlock()
if err := c.flush(); err != nil {
ec <- errors.Wrap(err, "Failed flush")
}
Expand Down
6 changes: 3 additions & 3 deletions connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func needCloseConn(err error) bool {
if err == nil {
return false
}
errcouse := errors.Cause(err)
return errcouse == ErrBadConn ||
errcouse == ErrServer
errcause := errors.Cause(err)
return errcause == ErrBadConn ||
errcause == ErrServer
}

0 comments on commit 44e1861

Please sign in to comment.