| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package subconfigs
-
- import (
- "fmt"
-
- "git.x2erp.com/qdy/go-base/config/core"
- )
-
- // RedisConfig Redis配置
- type RedisConfig struct {
- core.BaseConfig
- Host string `yaml:"host" desc:"Redis服务器主机地址"`
- Port int `yaml:"port" desc:"Redis服务器端口"`
- Password string `yaml:"password" desc:"Redis密码"`
- DB int `yaml:"db" desc:"Redis数据库索引(0-15)"`
- PoolSize int `yaml:"pool_size" desc:"连接池大小"`
- DialTimeout int `yaml:"dial_timeout" desc:"连接超时时间(秒)"`
- ReadTimeout int `yaml:"read_timeout" desc:"读取超时时间(秒)"`
- WriteTimeout int `yaml:"write_timeout" desc:"写入超时时间(秒)"`
- IdleTimeout int `yaml:"idle_timeout" desc:"空闲连接超时时间(秒)"`
- MaxConnAge int `yaml:"max_conn_age" desc:"连接最大生命周期(秒)"`
- }
-
- func (c *RedisConfig) Description() string {
- return "Redis缓存数据库配置"
- }
-
- func NewRedisConfig() *RedisConfig {
- return &RedisConfig{}
- }
-
- func (c *RedisConfig) SetDefaults() {
- c.Port = 6379
- c.DB = 0
- c.PoolSize = 10
- c.DialTimeout = 5
- c.ReadTimeout = 3
- c.WriteTimeout = 3
- c.IdleTimeout = 300
- }
-
- func (c *RedisConfig) Load(data map[string]interface{}) error {
- return c.LoadFromYAML(data, c)
- }
-
- func (c *RedisConfig) Validate() error {
- if c.Host == "" {
- return fmt.Errorf("redis host is required")
- }
- return nil
- }
-
- func (c *RedisConfig) IsConfigured() bool {
- return c.Host != ""
- }
-
- // 自动注册
- func init() {
- core.Register("redis", &RedisConfig{})
- }
|