add cluster mode and tls configuration support for package gredis (#2936)

This commit is contained in:
Hunk
2023-09-05 19:23:17 +08:00
committed by GitHub
parent b9e2b05f04
commit 912316d765
2 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,7 @@ package redis
import (
"context"
"crypto/tls"
"time"
"github.com/redis/go-redis/v9"
@ -67,7 +68,7 @@ func New(config *gredis.Config) *Redis {
redisSentinel := opts.Failover()
redisSentinel.ReplicaOnly = config.SlaveOnly
client = redis.NewFailoverClient(redisSentinel)
} else if len(opts.Addrs) > 1 {
} else if len(opts.Addrs) > 1 || config.Cluster {
client = redis.NewClusterClient(opts.Cluster())
} else {
client = redis.NewClient(opts.Simple())
@ -135,4 +136,9 @@ func fillWithDefaultConfiguration(config *gredis.Config) {
if config.ReadTimeout == 0 {
config.ReadTimeout = -1
}
if config.TLSConfig == nil && config.TLS {
config.TLSConfig = &tls.Config{
InsecureSkipVerify: config.TLSSkipVerify,
}
}
}

View File

@ -39,6 +39,7 @@ type Config struct {
TLSSkipVerify bool `json:"tlsSkipVerify"` // Disables server name verification when connecting over TLS.
TLSConfig *tls.Config `json:"-"` // TLS Config to use. When set TLS will be negotiated.
SlaveOnly bool `json:"slaveOnly"` // Route all commands to slave read-only nodes.
Cluster bool `json:"cluster"` // Specifies whether cluster mode be used.
}
const (