mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 02:55:58 +08:00
feat: cache add single-flight and timing-wheel.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package redispubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var ctx = context.Background()
|
||||
|
||||
type Subscriber struct {
|
||||
client redis.UniversalClient
|
||||
channel string
|
||||
}
|
||||
|
||||
func NewSubscriber(client redis.UniversalClient, channel string) *Subscriber {
|
||||
return &Subscriber{client: client, channel: channel}
|
||||
}
|
||||
|
||||
func (s *Subscriber) OnMessage(callback func(string)) error {
|
||||
messageChannel := s.client.Subscribe(ctx, s.channel).Channel()
|
||||
go func() {
|
||||
for msg := range messageChannel {
|
||||
callback(msg.Payload)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user