package redis import ( "crypto/tls" "io" "git.i2edu.net/i2/go-zero/core/syncx" red "github.com/go-redis/redis" ) const ( defaultDatabase = 0 maxRetries = 3 idleConns = 8 ) var clientManager = syncx.NewResourceManager() func getClient(r *Redis) (*red.Client, error) { val, err := clientManager.GetResource(r.Addr, func() (io.Closer, error) { var tlsConfig *tls.Config if r.tls { tlsConfig = &tls.Config{ InsecureSkipVerify: true, } } store := red.NewClient(&red.Options{ Addr: r.Addr, Password: r.Pass, DB: defaultDatabase, MaxRetries: maxRetries, MinIdleConns: idleConns, TLSConfig: tlsConfig, }) store.WrapProcess(process) return store, nil }) if err != nil { return nil, err } return val.(*red.Client), nil }