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

Method GC

osscluster.go:692–717  ·  view source on GitHub ↗

GC removes unused nodes.

(generation uint32)

Source from the content-addressed store, hash-verified

690
691// GC removes unused nodes.
692func (c *clusterNodes) GC(generation uint32) {
693 var collected []*clusterNode
694
695 c.mu.Lock()
696
697 c.activeAddrs = c.activeAddrs[:0]
698 now := time.Now()
699 for addr, node := range c.nodes {
700 if node.Generation() >= generation {
701 c.activeAddrs = append(c.activeAddrs, addr)
702 if c.opt.RouteByLatency && node.LastLatencyMeasurement() < now.Add(-minLatencyMeasurementInterval).UnixNano() {
703 go node.updateLatency()
704 }
705 continue
706 }
707
708 delete(c.nodes, addr)
709 collected = append(collected, node)
710 }
711
712 c.mu.Unlock()
713
714 for _, node := range collected {
715 _ = node.Client.Close()
716 }
717}
718
719func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) {
720 return c.GetOrCreateWithNodeAddress(addr, "")

Callers 3

newClusterStateFunction · 0.80
TestBytesToStringGCFunction · 0.80
TestStringToBytesGCFunction · 0.80

Calls 5

GenerationMethod · 0.80
updateLatencyMethod · 0.80
AddMethod · 0.65
CloseMethod · 0.65

Tested by 2

TestBytesToStringGCFunction · 0.64
TestStringToBytesGCFunction · 0.64