Skip to content

Commit 14e1aad

Browse files
Merge branch 'master' into DOC-5472-time-series-doc-examples
2 parents f55fb2a + 162c3fb commit 14e1aad

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sentinel.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/redis/go-redis/v9/internal"
1717
"github.com/redis/go-redis/v9/internal/pool"
1818
"github.com/redis/go-redis/v9/internal/rand"
19+
"github.com/redis/go-redis/v9/internal/util"
1920
)
2021

2122
//------------------------------------------------------------------------------
@@ -271,6 +272,7 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
271272
// URL attributes (scheme, host, userinfo, resp.), query parameters using these
272273
// names will be treated as unknown parameters
273274
// - unknown parameter names will result in an error
275+
// - use "skip_verify=true" to ignore TLS certificate validation
274276
//
275277
// Example:
276278
//
@@ -378,6 +380,10 @@ func setupFailoverConnParams(u *url.URL, o *FailoverOptions) (*FailoverOptions,
378380
o.SentinelAddrs = append(o.SentinelAddrs, net.JoinHostPort(h, p))
379381
}
380382

383+
if o.TLSConfig != nil && q.has("skip_verify") {
384+
o.TLSConfig.InsecureSkipVerify = q.bool("skip_verify")
385+
}
386+
381387
// any parameters left?
382388
if r := q.remaining(); len(r) > 0 {
383389
return nil, fmt.Errorf("redis: unexpected option: %s", strings.Join(r, ", "))
@@ -782,7 +788,20 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
782788
for err := range errCh {
783789
errs = append(errs, err)
784790
}
785-
return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errors.Join(errs...))
791+
return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %s", joinErrors(errs))
792+
}
793+
794+
func joinErrors(errs []error) string {
795+
if len(errs) == 1 {
796+
return errs[0].Error()
797+
}
798+
799+
b := []byte(errs[0].Error())
800+
for _, err := range errs[1:] {
801+
b = append(b, '\n')
802+
b = append(b, err.Error()...)
803+
}
804+
return util.BytesToString(b)
786805
}
787806

788807
func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected bool) ([]string, error) {

sentinel_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@ func TestParseFailoverURL(t *testing.T) {
431431
ServerName: "localhost",
432432
}},
433433
},
434+
{
435+
url: "rediss://localhost:6379/5?master_name=test&skip_verify=true",
436+
o: &redis.FailoverOptions{SentinelAddrs: []string{"localhost:6379"}, MasterName: "test", DB: 5,
437+
TLSConfig: &tls.Config{
438+
ServerName: "localhost",
439+
InsecureSkipVerify: true,
440+
}},
441+
},
434442
{
435443
url: "redis://localhost:6379/5?master_name=test&db=2",
436444
o: &redis.FailoverOptions{SentinelAddrs: []string{"localhost:6379"}, MasterName: "test", DB: 2},

0 commit comments

Comments
 (0)