redisclustermanager.go 607 B

1234567891011121314151617181920212223242526272829
  1. package redis
  2. import (
  3. "io"
  4. red "github.com/go-redis/redis"
  5. "github.com/tal-tech/go-zero/core/syncx"
  6. )
  7. var clusterManager = syncx.NewResourceManager()
  8. func getCluster(server, pass string) (*red.ClusterClient, error) {
  9. val, err := clusterManager.GetResource(server, func() (io.Closer, error) {
  10. store := red.NewClusterClient(&red.ClusterOptions{
  11. Addrs: []string{server},
  12. Password: pass,
  13. MaxRetries: maxRetries,
  14. MinIdleConns: idleConns,
  15. })
  16. store.WrapProcess(process)
  17. return store, nil
  18. })
  19. if err != nil {
  20. return nil, err
  21. }
  22. return val.(*red.ClusterClient), nil
  23. }