1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

v2: Remove timed out connection from the pool.

This commit is contained in:
Vladimir Mihailenco
2013-09-17 10:35:52 +03:00
parent dc90e359e9
commit 73b92efa94
3 changed files with 18 additions and 25 deletions

View File

@ -4,6 +4,8 @@ type PipelineClient struct {
*Client
}
// TODO: rename to Pipeline
// TODO: return just *PipelineClient
func (c *Client) PipelineClient() (*PipelineClient, error) {
return &PipelineClient{
Client: &Client{
@ -39,6 +41,8 @@ func (c *PipelineClient) DiscardQueued() {
c.reqsMtx.Unlock()
}
// TODO: rename to Run or ...
// TODO: should return error if one of the commands failed
func (c *PipelineClient) RunQueued() ([]Req, error) {
c.reqsMtx.Lock()
reqs := c.reqs
@ -49,18 +53,17 @@ func (c *PipelineClient) RunQueued() ([]Req, error) {
return []Req{}, nil
}
conn, err := c.conn()
cn, err := c.conn()
if err != nil {
return nil, err
}
err = c.runReqs(reqs, conn)
if err != nil {
c.removeConn(conn)
if err := c.runReqs(reqs, cn); err != nil {
c.removeConn(cn)
return nil, err
}
c.putConn(conn)
c.putConn(cn)
return reqs, nil
}