1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-07-03 11:53:41 +02:00

transport/redis_pubsub/redis.go rename to publisher.go

This commit is contained in:
Henrik Hautakoski 2023-03-07 11:33:53 +01:00
parent b46c070948
commit 19b93495ee
3 changed files with 11 additions and 11 deletions

View file

@ -0,0 +1,32 @@
package redis_pubsub
import (
"context"
"eosio-ship-trace-reader/transport"
"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) Publish(channel transport.ChannelInterface, 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
}