上传redis的数据卷参数

This commit is contained in:
liwei1dao 2022-07-04 10:29:29 +08:00
parent d1ae2a1878
commit eb803e8ddb
2 changed files with 17 additions and 3 deletions

4
sys/cache/cache.go vendored
View File

@ -28,7 +28,9 @@ func (this *Cache) init() (err error) {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Single),
redis.SetRedis_Single_Addr(this.options.Redis_Addr[0]),
redis.SetRedis_Single_Password(this.options.Redis_Password))
redis.SetRedis_Single_Password(this.options.Redis_Password),
redis.SetRedis_Single_DB(this.options.Redis_DB),
)
}
return
}

16
sys/cache/options.go vendored
View File

@ -14,6 +14,7 @@ type Options struct {
Redis_IsCluster bool //是否是集群
Redis_Addr []string //redis 的集群地址
Redis_Password string //redis的密码
Redis_DB int //数据库位置
}
//设置系统的集群地址
@ -37,9 +38,18 @@ func Set_Redis_Password(v string) Option {
}
}
//设置redis的数据存储卷
func Set_Redis_DB(v int) Option {
return func(o *Options) {
o.Redis_DB = v
}
}
//更具 map对象或者Option 序列化 系统参数对象
func newOptions(config map[string]interface{}, opts ...Option) (Options, error) {
options := Options{}
options := Options{
Redis_DB: 1,
}
if config != nil {
mapstructure.Decode(config, &options)
}
@ -54,7 +64,9 @@ func newOptions(config map[string]interface{}, opts ...Option) (Options, error)
//更具 Option 序列化 系统参数对象
func newOptionsByOption(opts ...Option) (Options, error) {
options := Options{}
options := Options{
Redis_DB: 1,
}
for _, o := range opts {
o(&options)
}