Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion contrib/nosql/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package redis

import (
"context"
"crypto/tls"
"time"

"github.com/redis/go-redis/v9"
Expand Down Expand Up @@ -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())
joy999 marked this conversation as resolved.
Show resolved Hide resolved
} else {
client = redis.NewClient(opts.Simple())
Expand Down Expand Up @@ -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,
}
}
}
1 change: 1 addition & 0 deletions database/gredis/gredis_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading