1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-20 09:56:47 +02:00
thalos/transport/redis_pubsub/publisher.go

33 lines
681 B
Go

package redis_pubsub
import (
"context"
"eosio-ship-trace-reader/transport"
. "eosio-ship-trace-reader/transport/redis_common"
"github.com/go-redis/redis/v8"
)
type Publisher struct {
pipeline redis.Pipeliner
ctx context.Context
ns Namespace
}
func NewPublisher(client *redis.Client, ns Namespace) *Publisher {
return &Publisher{
pipeline: client.Pipeline(),
ctx: client.Context(),
ns: ns,
}
}
func (r *Publisher) Write(channel transport.Channel, payload []byte) error {
return r.pipeline.Publish(r.ctx, r.ns.NewKey(channel).String(), payload).Err()
}
func (r *Publisher) Flush() error {
_, err := r.pipeline.Exec(r.ctx)
return err
}