github.com/lingyao2333/mo-zero@v1.4.1/core/stores/redis/redisclustermanager.go (about) 1 package redis 2 3 import ( 4 "crypto/tls" 5 "io" 6 7 red "github.com/go-redis/redis/v8" 8 "github.com/lingyao2333/mo-zero/core/syncx" 9 ) 10 11 var clusterManager = syncx.NewResourceManager() 12 13 func getCluster(r *Redis) (*red.ClusterClient, error) { 14 val, err := clusterManager.GetResource(r.Addr, func() (io.Closer, error) { 15 var tlsConfig *tls.Config 16 if r.tls { 17 tlsConfig = &tls.Config{ 18 InsecureSkipVerify: true, 19 } 20 } 21 store := red.NewClusterClient(&red.ClusterOptions{ 22 Addrs: []string{r.Addr}, 23 Password: r.Pass, 24 MaxRetries: maxRetries, 25 MinIdleConns: idleConns, 26 TLSConfig: tlsConfig, 27 }) 28 store.AddHook(durationHook) 29 30 return store, nil 31 }) 32 if err != nil { 33 return nil, err 34 } 35 36 return val.(*red.ClusterClient), nil 37 }