Skip to content

Commit c36b579

Browse files
committed
3021_add_subscriptionMap_log_subscription
1 parent 8e020c1 commit c36b579

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

extra/rediscensus/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ require (
1919
)
2020

2121
retract (
22-
v9.5.3 // This version was accidentally released.
2322
v9.7.2 // This version was accidentally released.
23+
v9.5.3 // This version was accidentally released.
2424
)

extra/rediscmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ require (
1616
)
1717

1818
retract (
19-
v9.5.3 // This version was accidentally released.
2019
v9.7.2 // This version was accidentally released.
20+
v9.5.3 // This version was accidentally released.
2121
)

extra/redisotel/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ require (
2424
)
2525

2626
retract (
27-
v9.5.3 // This version was accidentally released.
2827
v9.7.2 // This version was accidentally released.
28+
v9.5.3 // This version was accidentally released.
2929
)

extra/redisprometheus/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ require (
2323
)
2424

2525
retract (
26-
v9.5.3 // This version was accidentally released.
2726
v9.7.2 // This version was accidentally released.
27+
v9.5.3 // This version was accidentally released.
2828
)

pubsub.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis
33
import (
44
"context"
55
"fmt"
6+
"sort"
67
"strings"
78
"sync"
89
"time"
@@ -571,6 +572,9 @@ type channel struct {
571572
chanSize int
572573
chanSendTimeout time.Duration
573574
checkInterval time.Duration
575+
576+
subscriptions map[string]struct{}
577+
subscriptionsMu sync.RWMutex
574578
}
575579

576580
func newChannel(pubSub *PubSub, opts ...ChannelOption) *channel {
@@ -580,6 +584,8 @@ func newChannel(pubSub *PubSub, opts ...ChannelOption) *channel {
580584
chanSize: 100,
581585
chanSendTimeout: time.Minute,
582586
checkInterval: 3 * time.Second,
587+
588+
subscriptions: make(map[string]struct{}),
583589
}
584590
for _, opt := range opts {
585591
opt(c)
@@ -618,6 +624,20 @@ func (c *channel) initHealthCheck() {
618624
}()
619625
}
620626

627+
// Helper function to format subscription information
628+
func (c *channel) getSubscriptionInfo() string {
629+
if len(c.subscriptions) == 0 {
630+
return "none"
631+
}
632+
633+
subs := make([]string, 0, len(c.subscriptions))
634+
for sub := range c.subscriptions {
635+
subs = append(subs, sub)
636+
}
637+
sort.Strings(subs) // Sort for consistent output
638+
return strings.Join(subs, ", ")
639+
}
640+
621641
// initMsgChan must be in sync with initAllChan.
622642
func (c *channel) initMsgChan() {
623643
ctx := context.TODO()
@@ -663,9 +683,13 @@ func (c *channel) initMsgChan() {
663683
<-timer.C
664684
}
665685
case <-timer.C:
686+
c.subscriptionsMu.RLock()
687+
subInfo := c.getSubscriptionInfo()
688+
c.subscriptionsMu.RUnlock()
689+
666690
internal.Logger.Printf(
667-
ctx, "redis: %s channel is full for %s (message is dropped)",
668-
c, c.chanSendTimeout)
691+
ctx, "redis: Channel is full for %s (message is dropped), subscriptions: %s",
692+
c.chanSendTimeout, subInfo)
669693
}
670694
default:
671695
internal.Logger.Printf(ctx, "redis: unknown message type: %T", msg)
@@ -717,9 +741,13 @@ func (c *channel) initAllChan() {
717741
<-timer.C
718742
}
719743
case <-timer.C:
744+
c.subscriptionsMu.RLock()
745+
subInfo := c.getSubscriptionInfo()
746+
c.subscriptionsMu.RUnlock()
747+
720748
internal.Logger.Printf(
721-
ctx, "redis: %s channel is full for %s (message is dropped)",
722-
c, c.chanSendTimeout)
749+
ctx, "redis: Channel is full for %s (message is dropped), subscriptions: %s",
750+
c.chanSendTimeout, subInfo)
723751
}
724752
default:
725753
internal.Logger.Printf(ctx, "redis: unknown message type: %T", msg)

0 commit comments

Comments
 (0)