| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package subconfigs
-
- import "fmt"
-
- // RedisConfig Redis配置
- type RedisConfig struct {
- BaseConfig
- Host string `yaml:"host"`
- Port int `yaml:"port"`
- Password string `yaml:"password"`
- DB int `yaml:"db"`
- PoolSize int `yaml:"pool_size"`
- DialTimeout int `yaml:"dial_timeout"`
- ReadTimeout int `yaml:"read_timeout"`
- WriteTimeout int `yaml:"write_timeout"`
- IdleTimeout int `yaml:"idle_timeout"`
- MaxConnAge int `yaml:"max_conn_age"`
- }
-
- 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() {
- Register("redis", &RedisConfig{})
- }
|