simplify redis tls implementation (#606)
This commit is contained in:
@@ -14,10 +14,10 @@ var (
|
||||
type (
|
||||
// A RedisConf is a redis config.
|
||||
RedisConf struct {
|
||||
Host string
|
||||
Type string `json:",default=node,options=node|cluster"`
|
||||
Pass string `json:",optional"`
|
||||
TLSFlag bool `json:",default=false,options=true|false"`
|
||||
Host string
|
||||
Type string `json:",default=node,options=node|cluster"`
|
||||
Pass string `json:",optional"`
|
||||
Tls bool `json:",default=false,options=true|false"`
|
||||
}
|
||||
|
||||
// A RedisKeyConf is a redis config with key.
|
||||
@@ -29,10 +29,18 @@ type (
|
||||
|
||||
// NewRedis returns a Redis.
|
||||
func (rc RedisConf) NewRedis() *Redis {
|
||||
if rc.TLSFlag {
|
||||
return NewRedisWithTLS(rc.Host, rc.Type, rc.TLSFlag, rc.Pass)
|
||||
var opts []Option
|
||||
if rc.Type == ClusterType {
|
||||
opts = append(opts, Cluster())
|
||||
}
|
||||
return NewRedis(rc.Host, rc.Type, rc.Pass)
|
||||
if len(rc.Pass) > 0 {
|
||||
opts = append(opts, WithPass(rc.Pass))
|
||||
}
|
||||
if rc.Tls {
|
||||
opts = append(opts, WithTLS())
|
||||
}
|
||||
|
||||
return New(rc.Host, opts...)
|
||||
}
|
||||
|
||||
// Validate validates the RedisConf.
|
||||
|
||||
Reference in New Issue
Block a user