From 1d649a15b78c0c06c39608295c7ef0ca77ddbc70 Mon Sep 17 00:00:00 2001 From: haoshengzhen Date: Fri, 19 Jun 2026 11:08:40 +0800 Subject: [PATCH] fix(redis): default sentinel ports per address Signed-off-by: haoshengzhen --- ...aoshengzhen-redis-sentinel-default-port.md | 2 ++ util/redisutil/redisutil.go | 2 +- util/redisutil/redisutil_test.go | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 changelog/haoshengzhen-redis-sentinel-default-port.md create mode 100644 util/redisutil/redisutil_test.go diff --git a/changelog/haoshengzhen-redis-sentinel-default-port.md b/changelog/haoshengzhen-redis-sentinel-default-port.md new file mode 100644 index 00000000000..8f4b2dfeec6 --- /dev/null +++ b/changelog/haoshengzhen-redis-sentinel-default-port.md @@ -0,0 +1,2 @@ +### Fixed +- Default missing Redis Sentinel ports per address when parsing `redis+sentinel` URLs. diff --git a/util/redisutil/redisutil.go b/util/redisutil/redisutil.go index f2beee2d862..8895816d42c 100644 --- a/util/redisutil/redisutil.go +++ b/util/redisutil/redisutil.go @@ -96,7 +96,7 @@ func getAddressesWithDefaults(u *url.URL) []string { for _, urlHost := range urlHosts { host, port, err := net.SplitHostPort(urlHost) if err != nil { - host = u.Host + host = strings.TrimPrefix(strings.TrimSuffix(urlHost, "]"), "[") } if host == "" { host = "localhost" diff --git a/util/redisutil/redisutil_test.go b/util/redisutil/redisutil_test.go new file mode 100644 index 00000000000..b4db19a4451 --- /dev/null +++ b/util/redisutil/redisutil_test.go @@ -0,0 +1,21 @@ +// Copyright 2021-2026, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md + +package redisutil + +import ( + "reflect" + "testing" +) + +func TestParseFailoverRedisUrlDefaultsPortPerAddress(t *testing.T) { + options, err := parseFailoverRedisUrl("redis+sentinel://sentinel-1,sentinel-2:26379/master") + if err != nil { + t.Fatal(err) + } + + want := []string{"sentinel-1:6379", "sentinel-2:26379"} + if !reflect.DeepEqual(options.SentinelAddrs, want) { + t.Fatalf("unexpected sentinel addrs: have %v, want %v", options.SentinelAddrs, want) + } +}