添加停止需要释放的资源

This commit is contained in:
Yun
2025-10-04 19:00:44 +08:00
parent 737eef2157
commit 81ce4f67d3
2 changed files with 12 additions and 0 deletions
+6
View File
@@ -113,6 +113,12 @@ func InitCluster(ctx context.Context, red redis.UniversalClient, keyPrefix strin
// Stop 停止集群定时器 // Stop 停止集群定时器
func (l *Cluster) Stop() { func (l *Cluster) Stop() {
close(l.stopChan) close(l.stopChan)
if l.cancel != nil {
l.cancel()
}
if l.usePriority && l.priority != nil {
l.priority.Close()
}
l.cleanHeartbeat(true) l.cleanHeartbeat(true)
l.wg.Wait() l.wg.Wait()
} }
+6
View File
@@ -166,6 +166,12 @@ func InitOnce(ctx context.Context, re redis.UniversalClient, keyPrefix string, c
// Close 停止集群定时器 // Close 停止集群定时器
func (l *Once) Close() { func (l *Once) Close() {
close(l.stopChan) close(l.stopChan)
if l.usePriority && l.priority != nil {
l.priority.Close()
}
if l.leader != nil {
l.leader.Close()
}
l.heartbeat.Close() l.heartbeat.Close()
l.cancel() l.cancel()
l.wg.Wait() l.wg.Wait()