mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
add cluster mode and tls configuration support for package gredis (#2936)
This commit is contained in:
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user