fix: 修复redis pub/sub模式竞态问题

This commit is contained in:
tbphp
2025-07-09 15:52:00 +08:00
parent 0fa92758d8
commit 9bd32d5885
5 changed files with 23 additions and 22 deletions

View File

@@ -60,7 +60,6 @@ func (s *CacheSyncer[T]) Get() T {
// Invalidate publishes a notification to all instances to reload their cache.
func (s *CacheSyncer[T]) Invalidate() error {
s.logger.Debug("publishing invalidation notification")
s.reload()
return s.store.Publish(s.channelName, []byte("reload"))
}
@@ -125,7 +124,7 @@ func (s *CacheSyncer[T]) listenForUpdates() {
case msg, ok := <-subscription.Channel():
if !ok {
s.logger.Warn("subscription channel closed, attempting to re-subscribe...")
break subscriberLoop // This will lead to closing the current subscription and retrying.
break subscriberLoop
}
s.logger.Debugf("received invalidation notification, payload: %s", string(msg.Payload))
if err := s.reload(); err != nil {