1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-08-31 21:08:14 +02:00

Adding transport/redis_pubsub publisher

This commit is contained in:
Henrik Hautakoski 2023-01-13 13:30:50 +01:00
parent 6b6a375228
commit 45bf043d8a
4 changed files with 70 additions and 2 deletions

View file

@ -0,0 +1,28 @@
package redis_pubsub
import (
"context"
redis "github.com/go-redis/redis/v8"
)
type RedisPubsub struct {
pipeline redis.Pipeliner
ctx context.Context
}
func New(client *redis.Client) *RedisPubsub {
return &RedisPubsub{
pipeline: client.Pipeline(),
ctx: client.Context(),
}
}
func (r *RedisPubsub) Publish(channel string, payload []byte) error {
return r.pipeline.Publish(r.ctx, channel, payload).Err()
}
func (r *RedisPubsub) Flush() error {
_, err := r.pipeline.Exec(r.ctx)
return err
}