github.com/shuguocloud/go-zero@v1.3.0/core/stores/redis/redisclientmanager.go (about) 1 package redis 2 3 import ( 4 "crypto/tls" 5 "io" 6 7 red "github.com/go-redis/redis" 8 "github.com/shuguocloud/go-zero/core/syncx" 9 ) 10 11 const ( 12 defaultDatabase = 0 13 maxRetries = 3 14 idleConns = 8 15 ) 16 17 var clientManager = syncx.NewResourceManager() 18 19 func getClient(r *Redis) (*red.Client, error) { 20 val, err := clientManager.GetResource(r.Addr, func() (io.Closer, error) { 21 var tlsConfig *tls.Config 22 if r.tls { 23 tlsConfig = &tls.Config{ 24 InsecureSkipVerify: true, 25 } 26 } 27 store := red.NewClient(&red.Options{ 28 Addr: r.Addr, 29 Password: r.Pass, 30 DB: defaultDatabase, 31 MaxRetries: maxRetries, 32 MinIdleConns: idleConns, 33 TLSConfig: tlsConfig, 34 }) 35 store.WrapProcess(checkDuration) 36 return store, nil 37 }) 38 if err != nil { 39 return nil, err 40 } 41 42 return val.(*red.Client), nil 43 }