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

30 lines
607 B
Go

4 years ago
package redis
import (
"io"
red "github.com/go-redis/redis"
"github.com/tal-tech/go-zero/core/syncx"
4 years ago
)
var clusterManager = syncx.NewResourceManager()
func getCluster(server, pass string) (*red.ClusterClient, error) {
val, err := clusterManager.GetResource(server, func() (io.Closer, error) {
store := red.NewClusterClient(&red.ClusterOptions{
Addrs: []string{server},
Password: pass,
MaxRetries: maxRetries,
MinIdleConns: idleConns,
})
store.WrapProcess(process)
return store, nil
})
if err != nil {
return nil, err
}
return val.(*red.ClusterClient), nil
}