MCPcopy
hub / github.com/redis/go-redis / removeConn

Method removeConn

internal/pool/pool.go:1508–1529  ·  view source on GitHub ↗

removeConn removes a connection from the pool's internal data structures. Returns true if the connection was present and removed, false otherwise.

(cn *Conn)

Source from the content-addressed store, hash-verified

1506// removeConn removes a connection from the pool's internal data structures.
1507// Returns true if the connection was present and removed, false otherwise.
1508func (p *ConnPool) removeConn(cn *Conn) bool {
1509 cid := cn.GetID()
1510 if _, exists := p.conns[cid]; !exists {
1511 return false
1512 }
1513 delete(p.conns, cid)
1514 atomic.AddUint32(&p.stats.StaleConns, 1)
1515
1516 // Decrement pool size counter when removing a connection
1517 if cn.pooled {
1518 p.poolSize.Add(-1)
1519 // this can be idle conn
1520 for idx, ic := range p.idleConns {
1521 if ic == cn {
1522 p.idleConns = append(p.idleConns[:idx], p.idleConns[idx+1:]...)
1523 p.idleConnsLen.Add(-1)
1524 break
1525 }
1526 }
1527 }
1528 return true
1529}
1530
1531func (p *ConnPool) closeConn(cn *Conn) error {
1532 return cn.Close()

Callers 3

removeConnWithLockMethod · 0.95
RetireConnsMethod · 0.95
FilterMethod · 0.95

Calls 2

GetIDMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected