代码拉取完成,页面将自动刷新
package source
import (
"github.com/go-redis/redis"
streams "gitee.com/qw_1215/glink"
"gitee.com/qw_1215/glink/flow"
)
// RedisSource implements Redis Pub/Sub Source
type RedisSource struct {
redisdb *redis.Client
channel string
out chan interface{}
}
// NewRedisSource returns new RedisSource instance
func NewRedisSource(config *redis.Options, channel string) (*RedisSource, error) {
redisdb := redis.NewClient(config)
pubsub := redisdb.Subscribe(channel)
// Wait for confirmation that subscription is created before publishing anything
if _, err := pubsub.Receive(); err != nil {
return nil, err
}
source := &RedisSource{
redisdb,
channel,
make(chan interface{}),
}
go source.init(pubsub.Channel())
return source, nil
}
func (rs *RedisSource) init(ch <-chan *redis.Message) {
for msg := range ch {
rs.out <- msg
}
}
// Via streams data through given flow
func (rs *RedisSource) Via(_flow streams.Flow) streams.Flow {
flow.DoStream(rs, _flow)
return _flow
}
// Out returns channel for sending data
func (rs *RedisSource) Out() <-chan interface{} {
return rs.out
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。