From 130f08d3f06364f3551ec2f4ad101a163a6d93ba Mon Sep 17 00:00:00 2001 From: Robin Joseph Date: Thu, 15 Oct 2020 16:29:43 -0700 Subject: [PATCH 1/2] v2.1.0 --- CHANGELOG.md | 8 ++++ README.md | 12 ++--- consumer.go | 39 +++++++++-------- consumer_test.go | 112 +++++++++++++++++++++++++---------------------- go.mod | 9 ++-- go.sum | 99 +++++++++++++++++++++++++++++++---------- producer.go | 18 ++++---- producer_test.go | 22 ++++++---- redis.go | 7 +-- redis_test.go | 9 ++-- 10 files changed, 208 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d0bd9..f930693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ + +## [v2.1.0](https://github.com/robinjoseph08/go-pg-migrations/compare/v2.0.0...v2.1.0) (2020-10-15) + +### Features + +* **redis:** allow passing in redis.UniversalClient + + ## [v2.0.0](https://github.com/robinjoseph08/go-pg-migrations/compare/v1.1.0...v2.0.0) (2020-05-26) diff --git a/README.md b/README.md index bfd049d..bda006b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # redisqueue -![Version](https://img.shields.io/badge/version-v2.0.0-green.svg) +![Version](https://img.shields.io/badge/version-v2.1.0-green.svg) [![GoDoc](https://godoc.org/github.com/robinjoseph08/redisqueue?status.svg)](https://pkg.go.dev/github.com/robinjoseph08/redisqueue/v2?tab=doc) [![Build Status](https://travis-ci.org/robinjoseph08/redisqueue.svg?branch=master)](https://travis-ci.org/robinjoseph08/redisqueue) [![Coverage Status](https://coveralls.io/repos/github/robinjoseph08/redisqueue/badge.svg?branch=master)](https://coveralls.io/github/robinjoseph08/redisqueue?branch=master) @@ -61,7 +61,8 @@ import ( ) func main() { - p, err := redisqueue.NewProducerWithOptions(&redisqueue.ProducerOptions{ + ctx := context.Background() + p, err := redisqueue.NewProducerWithContextOptions(&redisqueue.ProducerOptions{ StreamMaxLength: 10000, ApproximateMaxLength: true, }) @@ -70,7 +71,7 @@ func main() { } for i := 0; i < 1000; i++ { - err := p.Enqueue(&redisqueue.Message{ + err := p.EnqueueWithContext(ctx, &redisqueue.Message{ Stream: "redisqueue:test", Values: map[string]interface{}{ "index": i, @@ -100,7 +101,8 @@ import ( ) func main() { - c, err := redisqueue.NewConsumerWithOptions(&redisqueue.ConsumerOptions{ + ctx := context.Background() + c, err := redisqueue.NewConsumerWithContextOptions(ctx, &redisqueue.ConsumerOptions{ VisibilityTimeout: 60 * time.Second, BlockingTimeout: 5 * time.Second, ReclaimInterval: 1 * time.Second, @@ -121,7 +123,7 @@ func main() { }() fmt.Println("starting") - c.Run() + c.Run(ctx) fmt.Println("stopped") } diff --git a/consumer.go b/consumer.go index 73af3db..3d58f3c 100644 --- a/consumer.go +++ b/consumer.go @@ -1,12 +1,13 @@ package redisqueue import ( + "context" "net" "os" "sync" "time" - "github.com/go-redis/redis/v7" + "github.com/go-redis/redis/v8" "github.com/pkg/errors" ) @@ -58,7 +59,7 @@ type ConsumerOptions struct { RedisClient redis.UniversalClient // RedisOptions allows you to configure the underlying Redis connection. // More info here: - // https://pkg.go.dev/github.com/go-redis/redis/v7?tab=doc#Options. + // https://pkg.go.dev/github.com/go-redis/redis/v8?tab=doc#Options. // // This field is used if RedisClient field is nil. RedisOptions *RedisOptions @@ -98,15 +99,15 @@ var defaultConsumerOptions = &ConsumerOptions{ // to the hostname, GroupName to "redisqueue", VisibilityTimeout to 60 seconds, // BufferSize to 100, and Concurrency to 10. In most production environments, // you'll want to use NewConsumerWithOptions. -func NewConsumer() (*Consumer, error) { - return NewConsumerWithOptions(defaultConsumerOptions) +func NewConsumerWithContext(ctx context.Context) (*Consumer, error) { + return NewConsumerWithContextOptions(ctx, defaultConsumerOptions) } // NewConsumerWithOptions creates a Consumer with custom ConsumerOptions. If // Name is left empty, it defaults to the hostname; if GroupName is left empty, // it defaults to "redisqueue"; if BlockingTimeout is 0, it defaults to 5 // seconds; if ReclaimInterval is 0, it defaults to 1 second. -func NewConsumerWithOptions(options *ConsumerOptions) (*Consumer, error) { +func NewConsumerWithContextOptions(ctx context.Context, options *ConsumerOptions) (*Consumer, error) { hostname, _ := os.Hostname() if options.Name == "" { @@ -130,7 +131,7 @@ func NewConsumerWithOptions(options *ConsumerOptions) (*Consumer, error) { r = newRedisClient(options.RedisOptions) } - if err := redisPreflightChecks(r); err != nil { + if err := redisPreflightChecks(ctx, r); err != nil { return nil, err } @@ -182,7 +183,7 @@ func (c *Consumer) Register(stream string, fn ConsumerFunc) { // Run will terminate early. The same will happen if an error occurs when // creating the consumer group in Redis. Run will block until Shutdown is called // and all of the in-flight messages have been processed. -func (c *Consumer) Run() { +func (c *Consumer) Run(ctx context.Context) { if len(c.consumers) == 0 { c.Errors <- errors.New("at least one consumer function needs to be registered") return @@ -190,7 +191,7 @@ func (c *Consumer) Run() { for stream, consumer := range c.consumers { c.streams = append(c.streams, stream) - err := c.redis.XGroupCreateMkStream(stream, c.options.GroupName, consumer.id).Err() + err := c.redis.XGroupCreateMkStream(ctx, stream, c.options.GroupName, consumer.id).Err() // ignoring the BUSYGROUP error makes this a noop if err != nil && err.Error() != "BUSYGROUP Consumer Group name already exists" { c.Errors <- errors.Wrap(err, "error creating consumer group") @@ -202,8 +203,8 @@ func (c *Consumer) Run() { c.streams = append(c.streams, ">") } - go c.reclaim() - go c.poll() + go c.reclaim(ctx) + go c.poll(ctx) stop := newSignalHandler() go func() { @@ -214,7 +215,7 @@ func (c *Consumer) Run() { c.wg.Add(c.options.Concurrency) for i := 0; i < c.options.Concurrency; i++ { - go c.work() + go c.work(ctx) } c.wg.Wait() @@ -237,7 +238,7 @@ func (c *Consumer) Shutdown() { // If VisibilityTimeout is 0, this function returns early and no messages are // reclaimed. It checks the list of pending messages according to // ReclaimInterval. -func (c *Consumer) reclaim() { +func (c *Consumer) reclaim(ctx context.Context) { if c.options.VisibilityTimeout == 0 { return } @@ -256,7 +257,7 @@ func (c *Consumer) reclaim() { end := "+" for { - res, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + res, err := c.redis.XPendingExt(ctx, &redis.XPendingExtArgs{ Stream: stream, Group: c.options.GroupName, Start: start, @@ -276,7 +277,7 @@ func (c *Consumer) reclaim() { for _, r := range res { if r.Idle >= c.options.VisibilityTimeout { - claimres, err := c.redis.XClaim(&redis.XClaimArgs{ + claimres, err := c.redis.XClaim(ctx, &redis.XClaimArgs{ Stream: stream, Group: c.options.GroupName, Consumer: c.options.Name, @@ -297,7 +298,7 @@ func (c *Consumer) reclaim() { // exists, the only way we can get it out of the // pending state is to acknowledge it. if err == redis.Nil { - err = c.redis.XAck(stream, c.options.GroupName, r.ID).Err() + err = c.redis.XAck(ctx, stream, c.options.GroupName, r.ID).Err() if err != nil { c.Errors <- errors.Wrapf(err, "error acknowledging after failed claim for %q stream and %q message", stream, r.ID) continue @@ -324,7 +325,7 @@ func (c *Consumer) reclaim() { // messages for this consumer to process. It blocks for up to 5 seconds instead // of blocking indefinitely so that it can periodically check to see if Shutdown // was called. -func (c *Consumer) poll() { +func (c *Consumer) poll(ctx context.Context) { for { select { case <-c.stopPoll: @@ -335,7 +336,7 @@ func (c *Consumer) poll() { } return default: - res, err := c.redis.XReadGroup(&redis.XReadGroupArgs{ + res, err := c.redis.XReadGroup(ctx, &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: c.options.Name, Streams: c.streams, @@ -378,7 +379,7 @@ func (c *Consumer) enqueue(stream string, msgs []redis.XMessage) { // channel, it calls the corrensponding ConsumerFunc depending on the stream it // came from. If no error is returned from the ConsumerFunc, the message is // acknowledged in Redis. -func (c *Consumer) work() { +func (c *Consumer) work(ctx context.Context) { defer c.wg.Done() for { @@ -389,7 +390,7 @@ func (c *Consumer) work() { c.Errors <- errors.Wrapf(err, "error calling ConsumerFunc for %q stream and %q message", msg.Stream, msg.ID) continue } - err = c.redis.XAck(msg.Stream, c.options.GroupName, msg.ID).Err() + err = c.redis.XAck(ctx, msg.Stream, c.options.GroupName, msg.ID).Err() if err != nil { c.Errors <- errors.Wrapf(err, "error acknowledging after success for %q stream and %q message", msg.Stream, msg.ID) continue diff --git a/consumer_test.go b/consumer_test.go index 844ae6f..e690067 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -1,19 +1,21 @@ package redisqueue import ( + "context" "os" "testing" "time" - "github.com/go-redis/redis/v7" + "github.com/go-redis/redis/v8" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestNewConsumer(t *testing.T) { + ctx := context.Background() t.Run("creates a new consumer", func(tt *testing.T) { - c, err := NewConsumer() + c, err := NewConsumerWithContext(ctx) require.NoError(tt, err) assert.NotNil(tt, c) @@ -21,15 +23,16 @@ func TestNewConsumer(t *testing.T) { } func TestNewConsumerWithOptions(t *testing.T) { + ctx := context.Background() t.Run("creates a new consumer", func(tt *testing.T) { - c, err := NewConsumerWithOptions(&ConsumerOptions{}) + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{}) require.NoError(tt, err) assert.NotNil(tt, c) }) t.Run("sets defaults for Name, GroupName, BlockingTimeout, and ReclaimTimeout", func(tt *testing.T) { - c, err := NewConsumerWithOptions(&ConsumerOptions{}) + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{}) require.NoError(tt, err) hostname, err := os.Hostname() @@ -44,7 +47,7 @@ func TestNewConsumerWithOptions(t *testing.T) { t.Run("allows override of Name, GroupName, BlockingTimeout, ReclaimTimeout, and RedisClient", func(tt *testing.T) { rc := newRedisClient(nil) - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ Name: "test_name", GroupName: "test_group_name", BlockingTimeout: 10 * time.Second, @@ -61,7 +64,7 @@ func TestNewConsumerWithOptions(t *testing.T) { }) t.Run("bubbles up errors", func(tt *testing.T) { - _, err := NewConsumerWithOptions(&ConsumerOptions{ + _, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ RedisOptions: &RedisOptions{Addr: "localhost:0"}, }) require.Error(tt, err) @@ -71,12 +74,13 @@ func TestNewConsumerWithOptions(t *testing.T) { } func TestRegister(t *testing.T) { + ctx := context.Background() fn := func(msg *Message) error { return nil } t.Run("set the function", func(tt *testing.T) { - c, err := NewConsumer() + c, err := NewConsumerWithContext(ctx) require.NoError(tt, err) c.Register(tt.Name(), fn) @@ -86,6 +90,7 @@ func TestRegister(t *testing.T) { } func TestRegisterWithLastID(t *testing.T) { + ctx := context.Background() fn := func(msg *Message) error { return nil } @@ -114,7 +119,7 @@ func TestRegisterWithLastID(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - c, err := NewConsumer() + c, err := NewConsumerWithContext(ctx) require.NoError(t, err) c.RegisterWithLastID("test", tt.id, fn) @@ -128,8 +133,9 @@ func TestRegisterWithLastID(t *testing.T) { } func TestRun(t *testing.T) { + ctx := context.Background() t.Run("sends an error if no ConsumerFuncs are registered", func(tt *testing.T) { - c, err := NewConsumer() + c, err := NewConsumerWithContext(ctx) require.NoError(tt, err) go func() { @@ -138,12 +144,12 @@ func TestRun(t *testing.T) { assert.Equal(tt, "at least one consumer function needs to be registered", err.Error()) }() - c.Run() + c.Run(ctx) }) t.Run("calls the ConsumerFunc on for a message", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ VisibilityTimeout: 60 * time.Second, BlockingTimeout: 10 * time.Millisecond, BufferSize: 100, @@ -152,15 +158,15 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducer() + p, err := NewProducerWithContext(ctx) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message - err = p.Enqueue(&Message{ + err = p.EnqueueWithContext(ctx, &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, }) @@ -181,12 +187,12 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) }) t.Run("reclaims pending messages according to ReclaimInterval", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ VisibilityTimeout: 5 * time.Millisecond, BlockingTimeout: 10 * time.Millisecond, ReclaimInterval: 1 * time.Millisecond, @@ -196,19 +202,19 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducer() + p, err := NewProducerWithContext(ctx) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message msg := &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, } - err = p.Enqueue(msg) + err = p.EnqueueWithContext(ctx, msg) require.NoError(tt, err) // register a handler that will assert the message and then shut down @@ -220,7 +226,7 @@ func TestRun(t *testing.T) { }) // read the message but don't acknowledge it - res, err := c.redis.XReadGroup(&redis.XReadGroupArgs{ + res, err := c.redis.XReadGroup(ctx, &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -242,12 +248,12 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) }) t.Run("doesn't reclaim if there is no VisibilityTimeout set", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ BlockingTimeout: 10 * time.Millisecond, ReclaimInterval: 1 * time.Millisecond, BufferSize: 100, @@ -256,15 +262,15 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducerWithOptions(&ProducerOptions{ + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{ StreamMaxLength: 2, ApproximateMaxLength: false, }) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message msg1 := &Message{ @@ -275,7 +281,7 @@ func TestRun(t *testing.T) { Stream: tt.Name(), Values: map[string]interface{}{"test": "value2"}, } - err = p.Enqueue(msg1) + err = p.EnqueueWithContext(ctx, msg1) require.NoError(tt, err) // register a handler that will assert the message and then shut down @@ -287,7 +293,7 @@ func TestRun(t *testing.T) { }) // read the message but don't acknowledge it - res, err := c.redis.XReadGroup(&redis.XReadGroupArgs{ + res, err := c.redis.XReadGroup(ctx, &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -299,7 +305,7 @@ func TestRun(t *testing.T) { require.Equal(tt, msg1.ID, res[0].Messages[0].ID) // add another message to the stream to let the consumer consume it - err = p.Enqueue(msg2) + err = p.EnqueueWithContext(ctx, msg2) require.NoError(tt, err) // watch for consumer errors @@ -309,10 +315,10 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) // check if the pending message is still there - pendingRes, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + pendingRes, err := c.redis.XPendingExt(ctx, &redis.XPendingExtArgs{ Stream: tt.Name(), Group: c.options.GroupName, Start: "-", @@ -326,7 +332,7 @@ func TestRun(t *testing.T) { t.Run("acknowledges pending messages that have already been deleted", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ VisibilityTimeout: 5 * time.Millisecond, BlockingTimeout: 10 * time.Millisecond, ReclaimInterval: 1 * time.Millisecond, @@ -336,22 +342,22 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducerWithOptions(&ProducerOptions{ + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{ StreamMaxLength: 1, ApproximateMaxLength: false, }) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message msg := &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, } - err = p.Enqueue(msg) + err = p.EnqueueWithContext(ctx, msg) require.NoError(tt, err) // register a noop handler that should never be called @@ -361,7 +367,7 @@ func TestRun(t *testing.T) { }) // read the message but don't acknowledge it - res, err := c.redis.XReadGroup(&redis.XReadGroupArgs{ + res, err := c.redis.XReadGroup(ctx, &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -373,7 +379,7 @@ func TestRun(t *testing.T) { require.Equal(tt, msg.ID, res[0].Messages[0].ID) // delete the message - err = c.redis.XDel(tt.Name(), msg.ID).Err() + err = c.redis.XDel(ctx, tt.Name(), msg.ID).Err() require.NoError(tt, err) // watch for consumer errors @@ -389,10 +395,10 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) // check that there are no pending messages - pendingRes, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + pendingRes, err := c.redis.XPendingExt(ctx, &redis.XPendingExtArgs{ Stream: tt.Name(), Group: c.options.GroupName, Start: "-", @@ -405,7 +411,7 @@ func TestRun(t *testing.T) { t.Run("returns an error on a string panic", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ VisibilityTimeout: 60 * time.Second, BlockingTimeout: 10 * time.Millisecond, BufferSize: 100, @@ -414,15 +420,15 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducer() + p, err := NewProducerWithContext(ctx) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message - err = p.Enqueue(&Message{ + err = p.EnqueueWithContext(ctx, &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, }) @@ -444,12 +450,12 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) }) t.Run("returns an error on an error panic", func(tt *testing.T) { // create a consumer - c, err := NewConsumerWithOptions(&ConsumerOptions{ + c, err := NewConsumerWithContextOptions(ctx, &ConsumerOptions{ VisibilityTimeout: 60 * time.Second, BlockingTimeout: 10 * time.Millisecond, BufferSize: 100, @@ -458,15 +464,15 @@ func TestRun(t *testing.T) { require.NoError(tt, err) // create a producer - p, err := NewProducer() + p, err := NewProducerWithContext(ctx) require.NoError(tt, err) // create consumer group - c.redis.XGroupDestroy(tt.Name(), c.options.GroupName) - c.redis.XGroupCreateMkStream(tt.Name(), c.options.GroupName, "$") + c.redis.XGroupDestroy(ctx, tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(ctx, tt.Name(), c.options.GroupName, "$") // enqueue a message - err = p.Enqueue(&Message{ + err = p.EnqueueWithContext(ctx, &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, }) @@ -488,6 +494,6 @@ func TestRun(t *testing.T) { }() // run the consumer - c.Run() + c.Run(ctx) }) } diff --git a/go.mod b/go.mod index c798d27..99dd767 100644 --- a/go.mod +++ b/go.mod @@ -6,18 +6,17 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.7.0 // indirect github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f - github.com/go-redis/redis/v7 v7.3.0 - github.com/golang/protobuf v1.3.3 // indirect + github.com/go-redis/redis/v8 v8.7.1 github.com/imdario/mergo v0.3.7 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/mattn/go-colorable v0.1.2 // indirect github.com/mattn/goveralls v0.0.2 github.com/pborman/uuid v1.2.0 // indirect github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.5.1 + github.com/stretchr/testify v1.7.0 github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect github.com/urfave/cli v1.20.0 // indirect - golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db // indirect gopkg.in/AlecAivazis/survey.v1 v1.8.5 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect - gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/go.sum b/go.sum index 2208032..49949d6 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,37 @@ github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f h1:8l4Aw3Jmx0pLKYMkY+1b6yBPgE+rzRtA5T3vqFyI2Z8= github.com/git-chglog/git-chglog v0.0.0-20190611050339-63a4e637021f/go.mod h1:Dcsy1kii/xFyNad5JqY/d0GO5mu91sungp5xotbm3Yk= -github.com/go-redis/redis/v7 v7.3.0 h1:3oHqd0W7f/VLKBxeYTEpqdMUsmMectngjM9OtoRoIgg= -github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= +github.com/go-redis/redis/v8 v8.7.1 h1:8IYi6RO83fNcG5amcUUYTN/qH2h4OjZHlim3KWGFSsA= +github.com/go-redis/redis/v8 v8.7.1/go.mod h1:BRxHBWn3pO3CfjyX6vAoyeRmCquvxr6QG+2onGV2gYs= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ= @@ -43,11 +58,16 @@ github.com/mattn/goveralls v0.0.2 h1:7eJB6EqsPhRVxvwEXGnqdO2sJI0PTsrWoTMXEk9/OQc github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= -github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= -github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= +github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= +github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -57,37 +77,73 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df h1:Y2l28Jr3vOEeYtxfVbMtVfOdAwuUqWaP9fvNKiBVeXY= github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df/go.mod h1:pnyouUty/nBr/zm3GYwTIt+qFTLWbdjeLjZmJdzJOu8= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/otel v0.18.0 h1:d5Of7+Zw4ANFOJB+TIn2K3QWsgS2Ht7OU9DqZHI6qu8= +go.opentelemetry.io/otel v0.18.0/go.mod h1:PT5zQj4lTsR1YeARt8YNKcFb88/c2IKoSABK9mX0r78= +go.opentelemetry.io/otel/metric v0.18.0 h1:yuZCmY9e1ZTaMlZXLrrbAPmYW6tW1A5ozOZeOYGaTaY= +go.opentelemetry.io/otel/metric v0.18.0/go.mod h1:kEH2QtzAyBy3xDVQfGZKIcok4ZZFvd5xyKPfPcuK6pE= +go.opentelemetry.io/otel/oteltest v0.18.0 h1:FbKDFm/LnQDOHuGjED+fy3s5YMVg0z019GJ9Er66hYo= +go.opentelemetry.io/otel/oteltest v0.18.0/go.mod h1:NyierCU3/G8DLTva7KRzGii2fdxdR89zXKH1bNWY7Bo= +go.opentelemetry.io/otel/trace v0.18.0 h1:ilCfc/fptVKaDMK1vWk0elxpolurJbEgey9J6g6s+wk= +go.opentelemetry.io/otel/trace v0.18.0/go.mod h1:FzdUu3BPwZSZebfQ1vl5/tAa8LyMLXSJN57AXIt/iDk= golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= -golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= -golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeBz87XgHAQuj+TbimYJuiw= -golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/AlecAivazis/survey.v1 v1.8.5 h1:QoEEmn/d5BbuPIL2qvXwzJdttFFhRQFkaq+tEKb7SMI= gopkg.in/AlecAivazis/survey.v1 v1.8.5/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= @@ -100,9 +156,8 @@ gopkg.in/kyokomi/emoji.v1 v1.5.1 h1:beetH5mWDMzFznJ+Qzd5KVHp79YKhVUMcdO8LpRLeGw= gopkg.in/kyokomi/emoji.v1 v1.5.1/go.mod h1:N9AZ6hi1jHOPn34PsbpufQZUcKftSD7WgS2pgpmH4Lg= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/producer.go b/producer.go index b52c028..3277cbb 100644 --- a/producer.go +++ b/producer.go @@ -1,7 +1,9 @@ package redisqueue import ( - "github.com/go-redis/redis/v7" + "context" + + "github.com/go-redis/redis/v8" ) // ProducerOptions provide options to configure the Producer. @@ -25,7 +27,7 @@ type ProducerOptions struct { RedisClient redis.UniversalClient // RedisOptions allows you to configure the underlying Redis connection. // More info here: - // https://pkg.go.dev/github.com/go-redis/redis/v7?tab=doc#Options. + // https://pkg.go.dev/github.com/go-redis/redis/v8?tab=doc#Options. // // This field is used if RedisClient field is nil. RedisOptions *RedisOptions @@ -46,12 +48,12 @@ var defaultProducerOptions = &ProducerOptions{ // NewProducer uses a default set of options to create a Producer. It sets // StreamMaxLength to 1000 and ApproximateMaxLength to true. In most production // environments, you'll want to use NewProducerWithOptions. -func NewProducer() (*Producer, error) { - return NewProducerWithOptions(defaultProducerOptions) +func NewProducerWithContext(ctx context.Context) (*Producer, error) { + return NewProducerWithContextOptions(ctx, defaultProducerOptions) } // NewProducerWithOptions creates a Producer using custom ProducerOptions. -func NewProducerWithOptions(options *ProducerOptions) (*Producer, error) { +func NewProducerWithContextOptions(ctx context.Context, options *ProducerOptions) (*Producer, error) { var r redis.UniversalClient if options.RedisClient != nil { @@ -60,7 +62,7 @@ func NewProducerWithOptions(options *ProducerOptions) (*Producer, error) { r = newRedisClient(options.RedisOptions) } - if err := redisPreflightChecks(r); err != nil { + if err := redisPreflightChecks(ctx, r); err != nil { return nil, err } @@ -74,7 +76,7 @@ func NewProducerWithOptions(options *ProducerOptions) (*Producer, error) { // msg.Stream. While you can set msg.ID, unless you know what you're doing, you // should let Redis auto-generate the ID. If an ID is auto-generated, it will be // set on msg.ID for your reference. msg.Values is also required. -func (p *Producer) Enqueue(msg *Message) error { +func (p *Producer) EnqueueWithContext(ctx context.Context, msg *Message) error { args := &redis.XAddArgs{ ID: msg.ID, Stream: msg.Stream, @@ -85,7 +87,7 @@ func (p *Producer) Enqueue(msg *Message) error { } else { args.MaxLen = p.options.StreamMaxLength } - id, err := p.redis.XAdd(args).Result() + id, err := p.redis.XAdd(ctx, args).Result() if err != nil { return err } diff --git a/producer_test.go b/producer_test.go index 6c00b9a..25303fc 100644 --- a/producer_test.go +++ b/producer_test.go @@ -1,6 +1,7 @@ package redisqueue import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -9,7 +10,8 @@ import ( func TestNewProducer(t *testing.T) { t.Run("creates a new producer", func(tt *testing.T) { - p, err := NewProducer() + ctx := context.Background() + p, err := NewProducerWithContext(ctx) require.NoError(tt, err) assert.NotNil(tt, p) @@ -17,8 +19,9 @@ func TestNewProducer(t *testing.T) { } func TestNewProducerWithOptions(t *testing.T) { + ctx := context.Background() t.Run("creates a new producer", func(tt *testing.T) { - p, err := NewProducerWithOptions(&ProducerOptions{}) + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{}) require.NoError(tt, err) assert.NotNil(tt, p) @@ -27,7 +30,7 @@ func TestNewProducerWithOptions(t *testing.T) { t.Run("allows custom *redis.Client", func(tt *testing.T) { rc := newRedisClient(nil) - p, err := NewProducerWithOptions(&ProducerOptions{ + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{ RedisClient: rc, }) require.NoError(tt, err) @@ -37,7 +40,7 @@ func TestNewProducerWithOptions(t *testing.T) { }) t.Run("bubbles up errors", func(tt *testing.T) { - _, err := NewProducerWithOptions(&ProducerOptions{ + _, err := NewProducerWithContextOptions(ctx, &ProducerOptions{ RedisOptions: &RedisOptions{Addr: "localhost:0"}, }) require.Error(tt, err) @@ -47,30 +50,31 @@ func TestNewProducerWithOptions(t *testing.T) { } func TestEnqueue(t *testing.T) { + ctx := context.Background() t.Run("puts the message in the stream", func(tt *testing.T) { - p, err := NewProducerWithOptions(&ProducerOptions{}) + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{}) require.NoError(t, err) msg := &Message{ Stream: tt.Name(), Values: map[string]interface{}{"test": "value"}, } - err = p.Enqueue(msg) + err = p.EnqueueWithContext(ctx, msg) require.NoError(tt, err) - res, err := p.redis.XRange(msg.Stream, msg.ID, msg.ID).Result() + res, err := p.redis.XRange(ctx, msg.Stream, msg.ID, msg.ID).Result() require.NoError(tt, err) assert.Equal(tt, "value", res[0].Values["test"]) }) t.Run("bubbles up errors", func(tt *testing.T) { - p, err := NewProducerWithOptions(&ProducerOptions{ApproximateMaxLength: true}) + p, err := NewProducerWithContextOptions(ctx, &ProducerOptions{ApproximateMaxLength: true}) require.NoError(t, err) msg := &Message{ Stream: tt.Name(), } - err = p.Enqueue(msg) + err = p.EnqueueWithContext(ctx, msg) require.Error(tt, err) assert.Contains(tt, err.Error(), "wrong number of arguments") diff --git a/redis.go b/redis.go index 0a5a68c..9716f0b 100644 --- a/redis.go +++ b/redis.go @@ -1,12 +1,13 @@ package redisqueue import ( + "context" "fmt" "regexp" "strconv" "strings" - "github.com/go-redis/redis/v7" + "github.com/go-redis/redis/v8" "github.com/pkg/errors" ) @@ -29,8 +30,8 @@ func newRedisClient(options *RedisOptions) *redis.Client { // offers the functionality we need. Specifically, it also that it can connect // to the actual instance and that the instance supports Redis streams (i.e. // it's at least v5). -func redisPreflightChecks(client redis.UniversalClient) error { - info, err := client.Info("server").Result() +func redisPreflightChecks(ctx context.Context, client redis.UniversalClient) error { + info, err := client.Info(ctx, "server").Result() if err != nil { return err } diff --git a/redis_test.go b/redis_test.go index 4614ab7..28bb88f 100644 --- a/redis_test.go +++ b/redis_test.go @@ -1,6 +1,7 @@ package redisqueue import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -8,28 +9,30 @@ import ( ) func TestNewRedisClient(t *testing.T) { + ctx := context.Background() t.Run("returns a new redis client", func(tt *testing.T) { options := &RedisOptions{} r := newRedisClient(options) - err := r.Ping().Err() + err := r.Ping(ctx).Err() assert.NoError(tt, err) }) t.Run("defaults options if it's nil", func(tt *testing.T) { r := newRedisClient(nil) - err := r.Ping().Err() + err := r.Ping(ctx).Err() assert.NoError(tt, err) }) } func TestRedisPreflightChecks(t *testing.T) { t.Run("bubbles up errors", func(tt *testing.T) { + ctx := context.Background() options := &RedisOptions{Addr: "localhost:0"} r := newRedisClient(options) - err := redisPreflightChecks(r) + err := redisPreflightChecks(ctx, r) require.Error(tt, err) assert.Contains(tt, err.Error(), "dial tcp") From 6a0788a71332d0e73812f91d7cc090cd0b654f08 Mon Sep 17 00:00:00 2001 From: Harishac Date: Tue, 23 Mar 2021 00:18:04 -0400 Subject: [PATCH 2/2] Update README examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bda006b..45cf0f3 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ import ( func main() { ctx := context.Background() - p, err := redisqueue.NewProducerWithContextOptions(&redisqueue.ProducerOptions{ + p, err := redisqueue.NewProducerWithContextOptions(ctx, &redisqueue.ProducerOptions{ StreamMaxLength: 10000, ApproximateMaxLength: true, })