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

Method RetireConns

internal/pool/pool.go:1579–1618  ·  view source on GitHub ↗
(ctx context.Context, conns []*Conn, reason string)

Source from the content-addressed store, hash-verified

1577}
1578
1579func (p *ConnPool) RetireConns(ctx context.Context, conns []*Conn, reason string) {
1580 if len(conns) == 0 {
1581 return
1582 }
1583
1584 idleConnSet := make(map[*Conn]struct{})
1585 toClose := make([]*Conn, 0, len(conns))
1586
1587 p.connsMu.Lock()
1588 for _, ic := range p.idleConns {
1589 idleConnSet[ic] = struct{}{}
1590 }
1591 for _, cn := range conns {
1592 if cn == nil {
1593 continue
1594 }
1595 if _, ok := p.conns[cn.GetID()]; !ok {
1596 continue
1597 }
1598 if _, isIdle := idleConnSet[cn]; isIdle {
1599 if p.removeConn(cn) {
1600 toClose = append(toClose, cn)
1601 }
1602 continue
1603 }
1604 cn.MarkCloseOnPut(reason)
1605 }
1606 p.connsMu.Unlock()
1607
1608 if hookManager := p.hookManager.Load(); hookManager != nil {
1609 for _, cn := range toClose {
1610 hookManager.ProcessOnRemove(ctx, cn, errors.New(reason))
1611 }
1612 }
1613 for _, cn := range toClose {
1614 p.recordConnectionMetrics(ctx, cn, reason, MetricStateIdle)
1615 _ = p.closeConn(cn)
1616 }
1617 p.checkMinIdleConns()
1618}
1619
1620func (p *ConnPool) Filter(fn func(*Conn) bool) error {
1621 ctx := context.Background()

Callers

nothing calls this directly

Calls 8

removeConnMethod · 0.95
closeConnMethod · 0.95
checkMinIdleConnsMethod · 0.95
GetIDMethod · 0.80
MarkCloseOnPutMethod · 0.80
ProcessOnRemoveMethod · 0.80
LoadMethod · 0.45

Tested by

no test coverage detected