From ea90145da7c21e5ad75005fe85d156e9df4e16cd Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Fri, 5 Feb 2021 12:17:45 -0800 Subject: [PATCH] Upgrade to go-redis/v8 There have been a number of fixes to go-redis for Redis Cluster compatibility. Notably, [1], which impacts the node go-redis chooses to send a stream command to. We're continuing to see `MOVED` errors emitted from redisqueue, despite not overriding `MaxRedirects` when constructing our redis client. This suggests to me that the choice of initial node may be to blame. This commit updates redisqueue to use go-redis/v8. In order to avoid signature changes, we use `context.TODO()` liberally. [1] https://github.com/go-redis/redis/issues/1501 --- consumer.go | 17 ++++----- consumer_test.go | 39 ++++++++++---------- go.mod | 9 +++-- go.sum | 93 ++++++++++++++++++++++++++++++++++++------------ producer.go | 8 +++-- producer_test.go | 3 +- redis.go | 5 +-- redis_test.go | 5 +-- 8 files changed, 117 insertions(+), 62 deletions(-) diff --git a/consumer.go b/consumer.go index 73af3db..b2d407a 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 @@ -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(context.TODO(), 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") @@ -256,7 +257,7 @@ func (c *Consumer) reclaim() { end := "+" for { - res, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + res, err := c.redis.XPendingExt(context.TODO(), &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(context.TODO(), &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(context.TODO(), 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 @@ -335,7 +336,7 @@ func (c *Consumer) poll() { } return default: - res, err := c.redis.XReadGroup(&redis.XReadGroupArgs{ + res, err := c.redis.XReadGroup(context.TODO(), &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: c.options.Name, Streams: c.streams, @@ -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(context.TODO(), 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..833f16e 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -1,11 +1,12 @@ 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" @@ -156,8 +157,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message err = p.Enqueue(&Message{ @@ -200,8 +201,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message msg := &Message{ @@ -220,7 +221,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(context.TODO(), &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -263,8 +264,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message msg1 := &Message{ @@ -287,7 +288,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(context.TODO(), &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -312,7 +313,7 @@ func TestRun(t *testing.T) { c.Run() // check if the pending message is still there - pendingRes, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + pendingRes, err := c.redis.XPendingExt(context.TODO(), &redis.XPendingExtArgs{ Stream: tt.Name(), Group: c.options.GroupName, Start: "-", @@ -343,8 +344,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message msg := &Message{ @@ -361,7 +362,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(context.TODO(), &redis.XReadGroupArgs{ Group: c.options.GroupName, Consumer: "failed_consumer", Streams: []string{tt.Name(), ">"}, @@ -373,7 +374,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(context.TODO(), tt.Name(), msg.ID).Err() require.NoError(tt, err) // watch for consumer errors @@ -392,7 +393,7 @@ func TestRun(t *testing.T) { c.Run() // check that there are no pending messages - pendingRes, err := c.redis.XPendingExt(&redis.XPendingExtArgs{ + pendingRes, err := c.redis.XPendingExt(context.TODO(), &redis.XPendingExtArgs{ Stream: tt.Name(), Group: c.options.GroupName, Start: "-", @@ -418,8 +419,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message err = p.Enqueue(&Message{ @@ -462,8 +463,8 @@ func TestRun(t *testing.T) { 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(context.TODO(), tt.Name(), c.options.GroupName) + c.redis.XGroupCreateMkStream(context.TODO(), tt.Name(), c.options.GroupName, "$") // enqueue a message err = p.Enqueue(&Message{ diff --git a/go.mod b/go.mod index c798d27..52a628c 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.5.0 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.6.1 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..71778d9 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.5.0 h1:L3r1Q3I5WOUdXZGCP6g44EruKh0u3n6co5Hl5xWkdGA= +github.com/go-redis/redis/v8 v8.5.0/go.mod h1:YmEcgBDttjnkbMzDAhDtQxY9yVA7jMN6PCR5HeMvqFE= 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,67 @@ 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.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/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.16.0 h1:uIWEbdeb4vpKPGITLsRVUS44L5oDbDUCZxn8lkxhmgw= +go.opentelemetry.io/otel v0.16.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= 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 +150,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..5d27de8 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 @@ -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(context.TODO(), args).Result() if err != nil { return err } diff --git a/producer_test.go b/producer_test.go index 6c00b9a..22c8db0 100644 --- a/producer_test.go +++ b/producer_test.go @@ -1,6 +1,7 @@ package redisqueue import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -58,7 +59,7 @@ func TestEnqueue(t *testing.T) { err = p.Enqueue(msg) require.NoError(tt, err) - res, err := p.redis.XRange(msg.Stream, msg.ID, msg.ID).Result() + res, err := p.redis.XRange(context.TODO(), msg.Stream, msg.ID, msg.ID).Result() require.NoError(tt, err) assert.Equal(tt, "value", res[0].Values["test"]) }) diff --git a/redis.go b/redis.go index 0a5a68c..7339ba1 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" ) @@ -30,7 +31,7 @@ func newRedisClient(options *RedisOptions) *redis.Client { // 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() + info, err := client.Info(context.TODO(), "server").Result() if err != nil { return err } diff --git a/redis_test.go b/redis_test.go index 4614ab7..11c5bce 100644 --- a/redis_test.go +++ b/redis_test.go @@ -1,6 +1,7 @@ package redisqueue import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -12,14 +13,14 @@ func TestNewRedisClient(t *testing.T) { options := &RedisOptions{} r := newRedisClient(options) - err := r.Ping().Err() + err := r.Ping(context.TODO()).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(context.TODO()).Err() assert.NoError(tt, err) }) }