package redis import ( "crypto/tls" "io" "git.i2edu.net/i2/go-zero/core/syncx" red "github.com/go-redis/redis" ) 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, } } store := red.NewClusterClient(&red.ClusterOptions{ Addrs: []string{r.Addr}, Password: r.Pass, MaxRetries: maxRetries, MinIdleConns: idleConns, TLSConfig: tlsConfig, }) store.WrapProcess(process) return store, nil }) if err != nil { return nil, err } return val.(*red.ClusterClient), nil }