memcache.go
func (c *Client) SetMaxIdleConnsPerAddr(maxIdle int) {
	if maxIdle == 0 {
		maxIdle = maxIdleConnsPerAddr
	}
	c.mu.Lock()
	defer c.mu.Unlock()
	c.maxIdlePerAddr = maxIdle
	if maxIdle > 0 {
		freeconn := make(map[string]chan *conn)
		for k, v := range c.freeconn {
			ch := make(chan *conn, maxIdle)
		ChanDone:
			for {
				select {
				case cn := <-v:
					select {
					case ch <- cn:
					default:
						cn.nc.Close()
					}
				default:
					freeconn[k] = ch
					break ChanDone
				}
			}
		}
		c.freeconn = freeconn
	} else {
		c.closeIdleConns()
		c.freeconn = nil
	}
}
func (c *Client) SetMaxIdleConnsPerAddr(maxIdle int) {
	if maxIdle == 0 {
		maxIdle = maxIdleConnsPerAddr
	}
	c.mu.Lock()
	defer c.mu.Unlock()
	c.maxIdlePerAddr = maxIdle
	if maxIdle > 0 {
		freeconn := make(map[string]chan *conn)
		for k, v := range c.freeconn {
			ch := make(chan *conn, maxIdle)
		ChanDone:
			for {
				select {
				case cn := <-v:
					select {
					case ch <- cn:
					default:
						cn.nc.Close()
					}
				default:
					freeconn[k] = ch
					break ChanDone
				}
			}
		}
		c.freeconn = freeconn
	} else {
		c.closeIdleConns()
		c.freeconn = nil
	}
}
func ( c * Client ) SetMaxIdleConnsPerAddr ( maxIdle int ) { if maxIdle == 0 { maxIdle = maxIdleConnsPerAddr } c . mu . Lock ( ) defer c . mu . Unlock ( ) c . maxIdlePerAddr = maxIdle if maxIdle > 0 { freeconn := make ( map [ string ] chan * conn ) for k , v := range c . freeconn { ch := make ( chan * conn , maxIdle ) ChanDone : for { select { case cn := <- v : select { case ch <- cn : default : cn . nc . Close ( ) } default : freeconn [ k ] = ch break ChanDone } } } c . freeconn = freeconn } else { c . closeIdleConns ( ) c . freeconn = nil } }
// SetMaxIdleConnsPerAddr changes the maximum number of
// idle connections kept per server. If maxIdle < 0,
// no idle connections are kept. If maxIdle == 0,
// the default number (currently 2) is used.
SetMaxIdleConnsPerAddr changes the maximum number of idle connections kept per server . If maxIdle < 0 no idle connections are kept . If maxIdle == 0 the default number ( currently 2 ) is used .