You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/stores/redis/redisclustermanager.go

38 lines
771 B
Go

4 years ago
package redis
import (
"crypto/tls"
4 years ago
"io"
red "github.com/go-redis/redis"
"github.com/tal-tech/go-zero/core/syncx"
4 years ago
)
var clusterManager = syncx.NewResourceManager()
func getCluster(r *Redis) (*red.ClusterClient, error) {
val, err := clusterManager.GetResource(r.Addr, func() (io.Closer, error) {
var tlsConfig *tls.Config
if r.tls {
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
4 years ago
store := red.NewClusterClient(&red.ClusterOptions{
Addrs: []string{r.Addr},
Password: r.Pass,
4 years ago
MaxRetries: maxRetries,
MinIdleConns: idleConns,
TLSConfig: tlsConfig,
4 years ago
})
store.WrapProcess(checkDuration(r.slowThreshold))
4 years ago
return store, nil
})
if err != nil {
return nil, err
}
return val.(*red.ClusterClient), nil
}