From 19b93495ee14361cbc553f9fd5389bf9704d8385 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 7 Mar 2023 11:33:53 +0100 Subject: [PATCH] transport/redis_pubsub/redis.go rename to publisher.go --- main.go | 2 +- transport/redis_pubsub/{redis.go => publisher.go} | 10 +++++----- .../redis_pubsub/{redis_test.go => publisher_test.go} | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) rename transport/redis_pubsub/{redis.go => publisher.go} (63%) rename transport/redis_pubsub/{redis_test.go => publisher_test.go} (59%) diff --git a/main.go b/main.go index fc35f41..46ebae9 100644 --- a/main.go +++ b/main.go @@ -222,7 +222,7 @@ func main() { app.SpawnProccessor( shClient, - redis_pubsub.New(rdb, redis_pubsub.Namespace{ + redis_pubsub.NewPublisher(rdb, redis_pubsub.Namespace{ Prefix: conf.Redis.Prefix, ChainID: chainInfo.ChainID.String(), }), diff --git a/transport/redis_pubsub/redis.go b/transport/redis_pubsub/publisher.go similarity index 63% rename from transport/redis_pubsub/redis.go rename to transport/redis_pubsub/publisher.go index 531fa9e..a651dd1 100644 --- a/transport/redis_pubsub/redis.go +++ b/transport/redis_pubsub/publisher.go @@ -8,25 +8,25 @@ import ( "github.com/go-redis/redis/v8" ) -type RedisPubsub struct { +type Publisher struct { pipeline redis.Pipeliner ctx context.Context ns Namespace } -func New(client *redis.Client, ns Namespace) *RedisPubsub { - return &RedisPubsub{ +func NewPublisher(client *redis.Client, ns Namespace) *Publisher { + return &Publisher{ pipeline: client.Pipeline(), ctx: client.Context(), ns: ns, } } -func (r *RedisPubsub) Publish(channel transport.ChannelInterface, payload []byte) error { +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 *RedisPubsub) Flush() error { +func (r *Publisher) Flush() error { _, err := r.pipeline.Exec(r.ctx) return err } diff --git a/transport/redis_pubsub/redis_test.go b/transport/redis_pubsub/publisher_test.go similarity index 59% rename from transport/redis_pubsub/redis_test.go rename to transport/redis_pubsub/publisher_test.go index 674f491..685f81e 100644 --- a/transport/redis_pubsub/redis_test.go +++ b/transport/redis_pubsub/publisher_test.go @@ -9,18 +9,18 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRedisPubsub(t *testing.T) { +func TestPublisher_Publish(t *testing.T) { client, mock := redismock.NewClientMock() - pubsub := New(client, Namespace{ChainID: "id"}) + pub := NewPublisher(client, Namespace{ChainID: "id"}) mock.MatchExpectationsInOrder(true) mock.ExpectPublish("ship::id::test", []byte("some string")).SetVal(0) mock.ExpectPublish("ship::id::test2", []byte("some other string")).SetVal(0) - assert.NoError(t, pubsub.Publish(transport.Channel{"test"}, []byte("some string"))) - assert.NoError(t, pubsub.Publish(transport.Channel{"test2"}, []byte("some other string"))) - assert.NoError(t, pubsub.Flush()) + assert.NoError(t, pub.Publish(transport.Channel{"test"}, []byte("some string"))) + assert.NoError(t, pub.Publish(transport.Channel{"test2"}, []byte("some other string"))) + assert.NoError(t, pub.Flush()) assert.NoError(t, mock.ExpectationsWereMet()) }