Skip to content

Commit 72c24d5

Browse files
authored
Merge branch 'master' into ndyakov/CAE-1088-resp3-notification-handlers
2 parents 4cd9853 + 162c3fb commit 72c24d5

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
@@ -17,6 +17,7 @@ import (
1717
"github.com/redis/go-redis/v9/internal/pool"
1818
"github.com/redis/go-redis/v9/internal/rand"
1919
"github.com/redis/go-redis/v9/push"
20+
"github.com/redis/go-redis/v9/internal/util"
2021
)
2122

2223
//------------------------------------------------------------------------------
@@ -274,6 +275,7 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
274275
// URL attributes (scheme, host, userinfo, resp.), query parameters using these
275276
// names will be treated as unknown parameters
276277
// - unknown parameter names will result in an error
278+
// - use "skip_verify=true" to ignore TLS certificate validation
277279
//
278280
// Example:
279281
//
@@ -381,6 +383,10 @@ func setupFailoverConnParams(u *url.URL, o *FailoverOptions) (*FailoverOptions,
381383
o.SentinelAddrs = append(o.SentinelAddrs, net.JoinHostPort(h, p))
382384
}
383385

386+
if o.TLSConfig != nil && q.has("skip_verify") {
387+
o.TLSConfig.InsecureSkipVerify = q.bool("skip_verify")
388+
}
389+
384390
// any parameters left?
385391
if r := q.remaining(); len(r) > 0 {
386392
return nil, fmt.Errorf("redis: unexpected option: %s", strings.Join(r, ", "))
@@ -806,7 +812,20 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
806812
for err := range errCh {
807813
errs = append(errs, err)
808814
}
809-
return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errors.Join(errs...))
815+
return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %s", joinErrors(errs))
816+
}
817+
818+
func joinErrors(errs []error) string {
819+
if len(errs) == 1 {
820+
return errs[0].Error()
821+
}
822+
823+
b := []byte(errs[0].Error())
824+
for _, err := range errs[1:] {
825+
b = append(b, '\n')
826+
b = append(b, err.Error()...)
827+
}
828+
return util.BytesToString(b)
810829
}
811830

812831
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)