Skip to content

Commit b3ef9e9

Browse files
authored
Upgrade go-redis/redis to version 8
1 parent 05534c6 commit b3ef9e9

24 files changed

+331
-304
lines changed

asynq.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/go-redis/redis/v7"
15+
"github.com/go-redis/redis/v8"
1616
"github.com/hibiken/asynq/internal/base"
1717
)
1818

asynq_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/go-redis/redis/v7"
13+
"github.com/go-redis/redis/v8"
1414
"github.com/google/go-cmp/cmp"
1515
h "github.com/hibiken/asynq/internal/asynqtest"
1616
"github.com/hibiken/asynq/internal/log"

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/go-redis/redis/v7"
13+
"github.com/go-redis/redis/v8"
1414
"github.com/google/uuid"
1515
"github.com/hibiken/asynq/internal/base"
1616
"github.com/hibiken/asynq/internal/errors"

client_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package asynq
66

77
import (
8+
"context"
89
"errors"
910
"testing"
1011
"time"
@@ -761,7 +762,7 @@ func TestClientEnqueueUnique(t *testing.T) {
761762
t.Fatal(err)
762763
}
763764

764-
gotTTL := r.TTL(base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
765+
gotTTL := r.TTL(context.Background(), base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
765766
if !cmp.Equal(tc.ttl.Seconds(), gotTTL.Seconds(), cmpopts.EquateApprox(0, 1)) {
766767
t.Errorf("TTL = %v, want %v", gotTTL, tc.ttl)
767768
continue
@@ -806,7 +807,7 @@ func TestClientEnqueueUniqueWithProcessInOption(t *testing.T) {
806807
t.Fatal(err)
807808
}
808809

809-
gotTTL := r.TTL(base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
810+
gotTTL := r.TTL(context.Background(), base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
810811
wantTTL := time.Duration(tc.ttl.Seconds()+tc.d.Seconds()) * time.Second
811812
if !cmp.Equal(wantTTL.Seconds(), gotTTL.Seconds(), cmpopts.EquateApprox(0, 1)) {
812813
t.Errorf("TTL = %v, want %v", gotTTL, wantTTL)
@@ -852,7 +853,7 @@ func TestClientEnqueueUniqueWithProcessAtOption(t *testing.T) {
852853
t.Fatal(err)
853854
}
854855

855-
gotTTL := r.TTL(base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
856+
gotTTL := r.TTL(context.Background(), base.UniqueKey(base.DefaultQueueName, tc.task.Type(), tc.task.Payload())).Val()
856857
wantTTL := tc.at.Add(tc.ttl).Sub(time.Now())
857858
if !cmp.Equal(wantTTL.Seconds(), gotTTL.Seconds(), cmpopts.EquateApprox(0, 1)) {
858859
t.Errorf("TTL = %v, want %v", gotTTL, wantTTL)

go.mod

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ module github.com/hibiken/asynq
33
go 1.13
44

55
require (
6-
github.com/go-redis/redis/v7 v7.4.0
7-
github.com/golang/protobuf v1.4.1
8-
github.com/google/go-cmp v0.5.0
6+
github.com/go-redis/redis/v8 v8.11.2
7+
github.com/golang/protobuf v1.4.2
8+
github.com/google/go-cmp v0.5.6
99
github.com/google/uuid v1.2.0
10+
github.com/kr/pretty v0.1.0 // indirect
1011
github.com/robfig/cron/v3 v3.0.1
1112
github.com/spf13/cast v1.3.1
13+
github.com/stretchr/testify v1.6.1 // indirect
1214
go.uber.org/goleak v0.10.0
13-
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e
15+
golang.org/x/sys v0.0.0-20210112080510-489259a85091
1416
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
1517
google.golang.org/protobuf v1.25.0
16-
gopkg.in/yaml.v2 v2.2.7 // indirect
18+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
1719
)

go.sum

+57-33
Large diffs are not rendered by default.

inspector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/go-redis/redis/v7"
13+
"github.com/go-redis/redis/v8"
1414
"github.com/google/uuid"
1515
"github.com/hibiken/asynq/internal/base"
1616
"github.com/hibiken/asynq/internal/errors"

inspector_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package asynq
66

77
import (
8+
"context"
89
"errors"
910
"fmt"
1011
"math"
@@ -37,7 +38,7 @@ func TestInspectorQueues(t *testing.T) {
3738
for _, tc := range tests {
3839
h.FlushDB(t, r)
3940
for _, qname := range tc.queues {
40-
if err := r.SAdd(base.AllQueues, qname).Err(); err != nil {
41+
if err := r.SAdd(context.Background(), base.AllQueues, qname).Err(); err != nil {
4142
t.Fatalf("could not initialize all queue set: %v", err)
4243
}
4344
}
@@ -136,7 +137,7 @@ func TestInspectorDeleteQueue(t *testing.T) {
136137
tc.qname, tc.force, err)
137138
continue
138139
}
139-
if r.SIsMember(base.AllQueues, tc.qname).Val() {
140+
if r.SIsMember(context.Background(), base.AllQueues, tc.qname).Val() {
140141
t.Errorf("%q is a member of %q", tc.qname, base.AllQueues)
141142
}
142143
}
@@ -345,11 +346,11 @@ func TestInspectorGetQueueInfo(t *testing.T) {
345346
h.SeedAllArchivedQueues(t, r, tc.archived)
346347
for qname, n := range tc.processed {
347348
processedKey := base.ProcessedKey(qname, now)
348-
r.Set(processedKey, n, 0)
349+
r.Set(context.Background(), processedKey, n, 0)
349350
}
350351
for qname, n := range tc.failed {
351352
failedKey := base.FailedKey(qname, now)
352-
r.Set(failedKey, n, 0)
353+
r.Set(context.Background(), failedKey, n, 0)
353354
}
354355

355356
got, err := inspector.GetQueueInfo(tc.qname)
@@ -385,14 +386,14 @@ func TestInspectorHistory(t *testing.T) {
385386
for _, tc := range tests {
386387
h.FlushDB(t, r)
387388

388-
r.SAdd(base.AllQueues, tc.qname)
389+
r.SAdd(context.Background(), base.AllQueues, tc.qname)
389390
// populate last n days data
390391
for i := 0; i < tc.n; i++ {
391392
ts := now.Add(-time.Duration(i) * 24 * time.Hour)
392393
processedKey := base.ProcessedKey(tc.qname, ts)
393394
failedKey := base.FailedKey(tc.qname, ts)
394-
r.Set(processedKey, (i+1)*1000, 0)
395-
r.Set(failedKey, (i+1)*10, 0)
395+
r.Set(context.Background(), processedKey, (i+1)*1000, 0)
396+
r.Set(context.Background(), failedKey, (i+1)*10, 0)
396397
}
397398

398399
got, err := inspector.History(tc.qname, tc.n)

internal/asynqtest/asynqtest.go

+26-25
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
package asynqtest
77

88
import (
9+
"context"
910
"encoding/json"
1011
"math"
1112
"sort"
1213
"testing"
1314
"time"
1415

15-
"github.com/go-redis/redis/v7"
16+
"github.com/go-redis/redis/v8"
1617
"github.com/google/go-cmp/cmp"
1718
"github.com/google/go-cmp/cmp/cmpopts"
1819
"github.com/google/uuid"
@@ -165,12 +166,12 @@ func FlushDB(tb testing.TB, r redis.UniversalClient) {
165166
tb.Helper()
166167
switch r := r.(type) {
167168
case *redis.Client:
168-
if err := r.FlushDB().Err(); err != nil {
169+
if err := r.FlushDB(context.Background()).Err(); err != nil {
169170
tb.Fatal(err)
170171
}
171172
case *redis.ClusterClient:
172-
err := r.ForEachMaster(func(c *redis.Client) error {
173-
if err := c.FlushAll().Err(); err != nil {
173+
err := r.ForEachMaster(context.Background(), func(ctx context.Context, c *redis.Client) error {
174+
if err := c.FlushAll(ctx).Err(); err != nil {
174175
return err
175176
}
176177
return nil
@@ -184,42 +185,42 @@ func FlushDB(tb testing.TB, r redis.UniversalClient) {
184185
// SeedPendingQueue initializes the specified queue with the given messages.
185186
func SeedPendingQueue(tb testing.TB, r redis.UniversalClient, msgs []*base.TaskMessage, qname string) {
186187
tb.Helper()
187-
r.SAdd(base.AllQueues, qname)
188+
r.SAdd(context.Background(), base.AllQueues, qname)
188189
seedRedisList(tb, r, base.PendingKey(qname), msgs, base.TaskStatePending)
189190
}
190191

191192
// SeedActiveQueue initializes the active queue with the given messages.
192193
func SeedActiveQueue(tb testing.TB, r redis.UniversalClient, msgs []*base.TaskMessage, qname string) {
193194
tb.Helper()
194-
r.SAdd(base.AllQueues, qname)
195+
r.SAdd(context.Background(), base.AllQueues, qname)
195196
seedRedisList(tb, r, base.ActiveKey(qname), msgs, base.TaskStateActive)
196197
}
197198

198199
// SeedScheduledQueue initializes the scheduled queue with the given messages.
199200
func SeedScheduledQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string) {
200201
tb.Helper()
201-
r.SAdd(base.AllQueues, qname)
202+
r.SAdd(context.Background(), base.AllQueues, qname)
202203
seedRedisZSet(tb, r, base.ScheduledKey(qname), entries, base.TaskStateScheduled)
203204
}
204205

205206
// SeedRetryQueue initializes the retry queue with the given messages.
206207
func SeedRetryQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string) {
207208
tb.Helper()
208-
r.SAdd(base.AllQueues, qname)
209+
r.SAdd(context.Background(), base.AllQueues, qname)
209210
seedRedisZSet(tb, r, base.RetryKey(qname), entries, base.TaskStateRetry)
210211
}
211212

212213
// SeedArchivedQueue initializes the archived queue with the given messages.
213214
func SeedArchivedQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string) {
214215
tb.Helper()
215-
r.SAdd(base.AllQueues, qname)
216+
r.SAdd(context.Background(), base.AllQueues, qname)
216217
seedRedisZSet(tb, r, base.ArchivedKey(qname), entries, base.TaskStateArchived)
217218
}
218219

219220
// SeedDeadlines initializes the deadlines set with the given entries.
220221
func SeedDeadlines(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string) {
221222
tb.Helper()
222-
r.SAdd(base.AllQueues, qname)
223+
r.SAdd(context.Background(), base.AllQueues, qname)
223224
seedRedisZSet(tb, r, base.DeadlinesKey(qname), entries, base.TaskStateActive)
224225
}
225226

@@ -278,7 +279,7 @@ func seedRedisList(tb testing.TB, c redis.UniversalClient, key string,
278279
tb.Helper()
279280
for _, msg := range msgs {
280281
encoded := MustMarshal(tb, msg)
281-
if err := c.LPush(key, msg.ID.String()).Err(); err != nil {
282+
if err := c.LPush(context.Background(), key, msg.ID.String()).Err(); err != nil {
282283
tb.Fatal(err)
283284
}
284285
key := base.TaskKey(msg.Queue, msg.ID.String())
@@ -289,11 +290,11 @@ func seedRedisList(tb testing.TB, c redis.UniversalClient, key string,
289290
"deadline": msg.Deadline,
290291
"unique_key": msg.UniqueKey,
291292
}
292-
if err := c.HSet(key, data).Err(); err != nil {
293+
if err := c.HSet(context.Background(), key, data).Err(); err != nil {
293294
tb.Fatal(err)
294295
}
295296
if len(msg.UniqueKey) > 0 {
296-
err := c.SetNX(msg.UniqueKey, msg.ID.String(), 1*time.Minute).Err()
297+
err := c.SetNX(context.Background(), msg.UniqueKey, msg.ID.String(), 1*time.Minute).Err()
297298
if err != nil {
298299
tb.Fatalf("Failed to set unique lock in redis: %v", err)
299300
}
@@ -308,7 +309,7 @@ func seedRedisZSet(tb testing.TB, c redis.UniversalClient, key string,
308309
msg := item.Message
309310
encoded := MustMarshal(tb, msg)
310311
z := &redis.Z{Member: msg.ID.String(), Score: float64(item.Score)}
311-
if err := c.ZAdd(key, z).Err(); err != nil {
312+
if err := c.ZAdd(context.Background(), key, z).Err(); err != nil {
312313
tb.Fatal(err)
313314
}
314315
key := base.TaskKey(msg.Queue, msg.ID.String())
@@ -319,11 +320,11 @@ func seedRedisZSet(tb testing.TB, c redis.UniversalClient, key string,
319320
"deadline": msg.Deadline,
320321
"unique_key": msg.UniqueKey,
321322
}
322-
if err := c.HSet(key, data).Err(); err != nil {
323+
if err := c.HSet(context.Background(), key, data).Err(); err != nil {
323324
tb.Fatal(err)
324325
}
325326
if len(msg.UniqueKey) > 0 {
326-
err := c.SetNX(msg.UniqueKey, msg.ID.String(), 1*time.Minute).Err()
327+
err := c.SetNX(context.Background(), msg.UniqueKey, msg.ID.String(), 1*time.Minute).Err()
327328
if err != nil {
328329
tb.Fatalf("Failed to set unique lock in redis: %v", err)
329330
}
@@ -398,13 +399,13 @@ func GetDeadlinesEntries(tb testing.TB, r redis.UniversalClient, qname string) [
398399
func getMessagesFromList(tb testing.TB, r redis.UniversalClient, qname string,
399400
keyFn func(qname string) string, state base.TaskState) []*base.TaskMessage {
400401
tb.Helper()
401-
ids := r.LRange(keyFn(qname), 0, -1).Val()
402+
ids := r.LRange(context.Background(), keyFn(qname), 0, -1).Val()
402403
var msgs []*base.TaskMessage
403404
for _, id := range ids {
404405
taskKey := base.TaskKey(qname, id)
405-
data := r.HGet(taskKey, "msg").Val()
406+
data := r.HGet(context.Background(), taskKey, "msg").Val()
406407
msgs = append(msgs, MustUnmarshal(tb, data))
407-
if gotState := r.HGet(taskKey, "state").Val(); gotState != state.String() {
408+
if gotState := r.HGet(context.Background(), taskKey, "state").Val(); gotState != state.String() {
408409
tb.Errorf("task (id=%q) is in %q state, want %v", id, gotState, state)
409410
}
410411
}
@@ -415,13 +416,13 @@ func getMessagesFromList(tb testing.TB, r redis.UniversalClient, qname string,
415416
func getMessagesFromZSet(tb testing.TB, r redis.UniversalClient, qname string,
416417
keyFn func(qname string) string, state base.TaskState) []*base.TaskMessage {
417418
tb.Helper()
418-
ids := r.ZRange(keyFn(qname), 0, -1).Val()
419+
ids := r.ZRange(context.Background(), keyFn(qname), 0, -1).Val()
419420
var msgs []*base.TaskMessage
420421
for _, id := range ids {
421422
taskKey := base.TaskKey(qname, id)
422-
msg := r.HGet(taskKey, "msg").Val()
423+
msg := r.HGet(context.Background(), taskKey, "msg").Val()
423424
msgs = append(msgs, MustUnmarshal(tb, msg))
424-
if gotState := r.HGet(taskKey, "state").Val(); gotState != state.String() {
425+
if gotState := r.HGet(context.Background(), taskKey, "state").Val(); gotState != state.String() {
425426
tb.Errorf("task (id=%q) is in %q state, want %v", id, gotState, state)
426427
}
427428
}
@@ -432,14 +433,14 @@ func getMessagesFromZSet(tb testing.TB, r redis.UniversalClient, qname string,
432433
func getMessagesFromZSetWithScores(tb testing.TB, r redis.UniversalClient,
433434
qname string, keyFn func(qname string) string, state base.TaskState) []base.Z {
434435
tb.Helper()
435-
zs := r.ZRangeWithScores(keyFn(qname), 0, -1).Val()
436+
zs := r.ZRangeWithScores(context.Background(), keyFn(qname), 0, -1).Val()
436437
var res []base.Z
437438
for _, z := range zs {
438439
taskID := z.Member.(string)
439440
taskKey := base.TaskKey(qname, taskID)
440-
msg := r.HGet(taskKey, "msg").Val()
441+
msg := r.HGet(context.Background(), taskKey, "msg").Val()
441442
res = append(res, base.Z{Message: MustUnmarshal(tb, msg), Score: int64(z.Score)})
442-
if gotState := r.HGet(taskKey, "state").Val(); gotState != state.String() {
443+
if gotState := r.HGet(context.Background(), taskKey, "state").Val(); gotState != state.String() {
443444
tb.Errorf("task (id=%q) is in %q state, want %v", taskID, gotState, state)
444445
}
445446
}

internal/base/base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"sync"
1515
"time"
1616

17-
"github.com/go-redis/redis/v7"
17+
"github.com/go-redis/redis/v8"
1818
"github.com/golang/protobuf/ptypes"
1919
"github.com/google/uuid"
2020
"github.com/hibiken/asynq/internal/errors"

0 commit comments

Comments
 (0)