Skip to content

Commit d4e9b79

Browse files
net/redistest: update go-redis client to work with redis:6 (#2949)
Update #2941 of go-redis to https://github.com/redis/go-redis/releases/tag/v9.5.0 broke support of redis:6 Unfortunately we did not catch it because we updated test redis to redis:7 recently, see #2895 This change updates go-redis to https://github.com/redis/go-redis/releases/tag/v9.5.1 and adds a test to verify it supports both redis:6 and redis:7 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
1 parent da3d600 commit d4e9b79

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
github.com/opentracing/opentracing-go v1.2.0
3535
github.com/prometheus/client_golang v1.18.0
3636
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
37-
github.com/redis/go-redis/v9 v9.5.0
37+
github.com/redis/go-redis/v9 v9.5.1
3838
github.com/sarslanhan/cronmask v0.0.0-20230801193303-54e29300a091
3939
github.com/sirupsen/logrus v1.9.3
4040
github.com/sony/gobreaker v0.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
351351
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
352352
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
353353
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
354-
github.com/redis/go-redis/v9 v9.5.0 h1:Xe9TKMmZv939gwTBcvc0n1tzK5l2re0pKw/W/tN3amw=
355-
github.com/redis/go-redis/v9 v9.5.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
354+
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
355+
github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
356356
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
357357
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
358358
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=

net/redistest/redistest.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ import (
1212
"github.com/testcontainers/testcontainers-go/wait"
1313
)
1414

15+
type options struct {
16+
password string
17+
image string
18+
}
19+
1520
func NewTestRedis(t testing.TB) (address string, done func()) {
16-
return NewTestRedisWithPassword(t, "")
21+
return newTestRedisWithOptions(t, options{})
1722
}
1823

1924
func NewTestRedisWithPassword(t testing.TB, password string) (address string, done func()) {
25+
return newTestRedisWithOptions(t, options{password: password})
26+
}
27+
28+
func newTestRedisWithOptions(t testing.TB, opts options) (address string, done func()) {
2029
var args []string
21-
if password != "" {
22-
args = append(args, "--requirepass", password)
30+
if opts.password != "" {
31+
args = append(args, "--requirepass", opts.password)
2332
}
2433

2534
start := time.Now()
@@ -38,9 +47,14 @@ func NewTestRedisWithPassword(t testing.TB, password string) (address string, do
3847
t.Fatalf("Failed to get new nat port: %v", err)
3948
}
4049

50+
image := "redis:7-alpine"
51+
if opts.image != "" {
52+
image = opts.image
53+
}
54+
4155
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
4256
ContainerRequest: testcontainers.ContainerRequest{
43-
Image: "redis:7-alpine",
57+
Image: image,
4458
Cmd: args,
4559
ExposedPorts: []string{"6379/tcp"},
4660
Networks: []string{network.Name},
@@ -66,7 +80,7 @@ func NewTestRedisWithPassword(t testing.TB, password string) (address string, do
6680

6781
t.Logf("Started redis server at %s in %v", address, time.Since(start))
6882

69-
if err := ping(ctx, address, password); err != nil {
83+
if err := ping(ctx, address, opts.password); err != nil {
7084
t.Fatalf("Failed to ping redis server: %v", err)
7185
}
7286

net/redistest/redistest_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ func TestRedistest(t *testing.T) {
1515
t.Fatalf("Failed to ping redis: %v", err)
1616
}
1717
}
18+
19+
func TestRedistestRedis6(t *testing.T) {
20+
r, done := newTestRedisWithOptions(t, options{image: "redis:6-alpine"})
21+
defer done()
22+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
23+
defer cancel()
24+
if err := ping(ctx, r, ""); err != nil {
25+
t.Fatalf("Failed to ping redis: %v", err)
26+
}
27+
}

0 commit comments

Comments
 (0)