func (r RedisMode) IsCluster() bool {
	return r == RedisModeCluster
}
IsCluster return current redis mode is cluster
package config
import (
	encodeJson "encoding/json"
	"errors"
	"github.com/changsongl/delay-queue/config/decode"
	"github.com/changsongl/delay-queue/config/decode/json"
	"github.com/changsongl/delay-queue/config/decode/yaml"
	"io/ioutil"
	"os"
)
type FileType string
const (
	FileTypeYAML FileType = "yaml"
	FileTypeJSON FileType = "json"
)
type RedisMode string
const (
	RedisModeNormal RedisMode = ""
	RedisModeCluster RedisMode = "cluster"
)
const (
	DefaultDQBindAddress       = ":8000"
	DefaultDQBucketName        = "dq_bucket"
	DefaultDQQueueName         = "dq_queue"
	DefaultDQBucketSize        = 8
	DefaultDQBucketMaxFetchNum = 200
	DefaultTimerFetchInterval  = 10000
	DefaultFetchJobBlockTime   = 5
	DefaultRedisNetwork      = "tcp"
	DefaultRedisAddress      = "127.0.0.1:6379"
	DefaultRedisDialTimeout  = 5000
	DefaultRedisReadTimeout  = 3000
	DefaultRedisWriteTimeout = 3000
)
type Conf struct {
	DelayQueue DelayQueue `yaml:"delay_queue,omitempty" json:"delay_queue,omitempty"`
	Redis      Redis      `yaml:"redis,omitempty" json:"redis,omitempty"`
}
type DelayQueue struct {
	BindAddress string `yaml:"bind_address,omitempty" json:"bind_address,omitempty"`
	BucketName string `yaml:"bucket_name,omitempty" json:"bucket_name,omitempty"`
	BucketSize uint64 `yaml:"bucket_size,omitempty" json:"bucket_size,omitempty"`
	BucketMaxFetchNum uint64 `yaml:"bucket_max_fetch_num,omitempty" json:"bucket_max_fetch_num,omitempty"`
	QueueName string `yaml:"queue_name,omitempty" json:"queue_name,omitempty"`
	TimerFetchInterval int `yaml:"timer_fetch_interval,omitempty" json:"timer_fetch_interval,omitempty"`
	TimerFetchDelay int `yaml:"timer_fetch_delay,omitempty" json:"timer_fetch_delay,omitempty"`
}
type Redis struct {
	Mode RedisMode `yaml:"mode,omitempty" json:"mode,omitempty"`
	Network string `yaml:"network,omitempty" json:"network,omitempty"`
	Address string `yaml:"address,omitempty" json:"address,omitempty"`
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Password string `yaml:"password,omitempty" json:"password,omitempty"`
	DB int `yaml:"db,omitempty" json:"db,omitempty"`
	DialTimeout int `yaml:"dial_timeout,omitempty" json:"dial_timeout,omitempty"`
	ReadTimeout int `yaml:"read_timeout,omitempty" json:"read_timeout,omitempty"`
	WriteTimeout int `yaml:"write_timeout,omitempty" json:"write_timeout,omitempty"`
	PoolSize int `yaml:"pool_size,omitempty" json:"pool_size,omitempty"`
	MinIdleConns int `yaml:"min_idle_conns,omitempty" json:"min_idle_conns,omitempty"`
}
func New() *Conf {
	return &Conf{
		DelayQueue: DelayQueue{
			BindAddress:        DefaultDQBindAddress,
			BucketName:         DefaultDQBucketName,
			BucketSize:         DefaultDQBucketSize,
			QueueName:          DefaultDQQueueName,
			BucketMaxFetchNum:  DefaultDQBucketMaxFetchNum,
			TimerFetchInterval: DefaultTimerFetchInterval,
		},
		Redis: Redis{
			Network:      DefaultRedisNetwork,
			Address:      DefaultRedisAddress,
			DialTimeout:  DefaultRedisDialTimeout,
			ReadTimeout:  DefaultRedisReadTimeout,
			WriteTimeout: DefaultRedisWriteTimeout,
		},
	}
}
func (c *Conf) Load(file string, fileType FileType) error {
	f, err := os.Open(file)
	if err != nil {
		return err
	}
	bts, err := ioutil.ReadAll(f)
	if err != nil {
		return err
	}
	decoder, err := c.getDecoderByFileType(fileType)
	if err != nil {
		return err
	}
	if err = c.load(bts, decoder.DecodeFunc()); err != nil {
		return err
	}
	return nil
}
func (c *Conf) load(bts []byte, decodeFunc func([]byte, interface{}) error) error {
	err := decodeFunc(bts, c)
	if err != nil {
		return nil
	}
	return nil
}
func (c *Conf) getDecoderByFileType(fileType FileType) (decode.Decoder, error) {
	if fileType == FileTypeJSON {
		return json.NewDecoder(), nil
	} else if fileType == FileTypeYAML {
		return yaml.NewDecoder(), nil
	}
	return nil, errors.New("invalid file type")
}
func (c *Conf) String() string {
	bytes, _ := encodeJson.Marshal(c)
	return string(bytes)
}