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:
parent
b46c070948
commit
19b93495ee
3 changed files with 11 additions and 11 deletions
32
transport/redis_pubsub/publisher.go
Normal file
32
transport/redis_pubsub/publisher.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue