redis增加tls支持 (#595)
* redis连接增加支持tls选项 * 优化redis tls config 写法 * redis增加tls支持 * 增加redis tls测试用例,但redis tls local server不支持,测试用例全部NotNil Co-authored-by: liuyi <liuyi@fangyb.com> Co-authored-by: yi.liu <yi.liu@xshoppy.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
|
||||
red "github.com/go-redis/redis"
|
||||
@@ -10,12 +11,23 @@ import (
|
||||
var clusterManager = syncx.NewResourceManager()
|
||||
|
||||
func getCluster(server, pass string) (*red.ClusterClient, error) {
|
||||
return getClusterWithTLS(server, pass, false)
|
||||
}
|
||||
|
||||
func getClusterWithTLS(server, pass string, tlsFlag bool) (*red.ClusterClient, error) {
|
||||
val, err := clusterManager.GetResource(server, func() (io.Closer, error) {
|
||||
var tlsConfig *tls.Config = nil
|
||||
if tlsFlag {
|
||||
tlsConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
}
|
||||
store := red.NewClusterClient(&red.ClusterOptions{
|
||||
Addrs: []string{server},
|
||||
Password: pass,
|
||||
MaxRetries: maxRetries,
|
||||
MinIdleConns: idleConns,
|
||||
TLSConfig: tlsConfig,
|
||||
})
|
||||
store.WrapProcess(process)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user