|
@@ -37,10 +37,11 @@ type (
|
|
|
|
|
|
// Redis defines a redis node/cluster. It is thread-safe.
|
|
// Redis defines a redis node/cluster. It is thread-safe.
|
|
Redis struct {
|
|
Redis struct {
|
|
- Addr string
|
|
|
|
- Type string
|
|
|
|
- Pass string
|
|
|
|
- brk breaker.Breaker
|
|
|
|
|
|
+ Addr string
|
|
|
|
+ Type string
|
|
|
|
+ Pass string
|
|
|
|
+ brk breaker.Breaker
|
|
|
|
+ TLSFlag bool
|
|
}
|
|
}
|
|
|
|
|
|
// RedisNode interface represents a redis node.
|
|
// RedisNode interface represents a redis node.
|
|
@@ -71,16 +72,21 @@ type (
|
|
|
|
|
|
// NewRedis returns a Redis.
|
|
// NewRedis returns a Redis.
|
|
func NewRedis(redisAddr, redisType string, redisPass ...string) *Redis {
|
|
func NewRedis(redisAddr, redisType string, redisPass ...string) *Redis {
|
|
|
|
+ return NewRedisWithTLS(redisAddr, redisType, false, redisPass...)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func NewRedisWithTLS(redisAddr, redisType string, tlsFlag bool, redisPass ...string) *Redis {
|
|
var pass string
|
|
var pass string
|
|
for _, v := range redisPass {
|
|
for _, v := range redisPass {
|
|
pass = v
|
|
pass = v
|
|
}
|
|
}
|
|
|
|
|
|
return &Redis{
|
|
return &Redis{
|
|
- Addr: redisAddr,
|
|
|
|
- Type: redisType,
|
|
|
|
- Pass: pass,
|
|
|
|
- brk: breaker.NewBreaker(),
|
|
|
|
|
|
+ Addr: redisAddr,
|
|
|
|
+ Type: redisType,
|
|
|
|
+ Pass: pass,
|
|
|
|
+ brk: breaker.NewBreaker(),
|
|
|
|
+ TLSFlag: tlsFlag,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1704,9 +1710,17 @@ func acceptable(err error) bool {
|
|
func getRedis(r *Redis) (RedisNode, error) {
|
|
func getRedis(r *Redis) (RedisNode, error) {
|
|
switch r.Type {
|
|
switch r.Type {
|
|
case ClusterType:
|
|
case ClusterType:
|
|
- return getCluster(r.Addr, r.Pass)
|
|
|
|
|
|
+ if r.TLSFlag {
|
|
|
|
+ return getClusterWithTLS(r.Addr, r.Pass, r.TLSFlag)
|
|
|
|
+ } else {
|
|
|
|
+ return getCluster(r.Addr, r.Pass)
|
|
|
|
+ }
|
|
case NodeType:
|
|
case NodeType:
|
|
- return getClient(r.Addr, r.Pass)
|
|
|
|
|
|
+ if r.TLSFlag {
|
|
|
|
+ return getClientWithTLS(r.Addr, r.Pass, r.TLSFlag)
|
|
|
|
+ } else {
|
|
|
|
+ return getClient(r.Addr, r.Pass)
|
|
|
|
+ }
|
|
default:
|
|
default:
|
|
return nil, fmt.Errorf("redis type '%s' is not supported", r.Type)
|
|
return nil, fmt.Errorf("redis type '%s' is not supported", r.Type)
|
|
}
|
|
}
|