bitleak/go-redis-pool

master-slave NewHA PollType: pool.PollByWeight colon problem

Closed this issue · 2 comments

dcggwp commented

github.com/bitleak/go-redis-pool/v3/ha_conn_factory.go line: 193

slaveOptions.Addr = slave // Do you need to handle the extra colons for PollByWeight here

// NewHAConnFactory create new ha factory
func newClientPool(cfg *HAConfig) *clientPool {
	slavePassword := cfg.Password
	if cfg.ReadonlyPassword != "" {
		slavePassword = cfg.ReadonlyPassword
	}

	pool := &clientPool{
		pollType:           cfg.PollType,
		autoEjectHost:      cfg.AutoEjectHost,
		serverFailureLimit: cfg.ServerFailureLimit,
		serverRetryTimeout: cfg.ServerRetryTimeout,
		minServerNum:       cfg.MinServerNum,

		stopCh: make(chan struct{}, 0),
		rand:   rand.New(rand.NewSource(time.Now().UnixNano())),
	}
	pool.slaves = make([]*client, len(cfg.Slaves))
	options := cfg.Options
	for i, slave := range cfg.Slaves {
		slaveOptions := *options
		slaveOptions.Addr = slave  //  Do you need to handle the extra colons for PollByWeight here
		slaveOptions.Password = slavePassword
		redisCli := redis.NewClient(&slaveOptions)
		cli := newClient(redisCli, cfg.weights[i])
		if cfg.AutoEjectHost && len(cfg.Slaves) > 1 {
			redisCli.AddHook(newFailureHook(cli))
		}
		pool.slaves[i] = cli
	}
	pool.alives = pool.slaves
	if pool.pollType == PollByWeight {
		weightRanges := make([]int64, len(pool.alives))
		weightRanges[0] = pool.alives[0].weight
		for i := 1; i < len(pool.alives); i++ {
			weightRanges[i] = weightRanges[i-1] + pool.alives[i].weight
		}
		pool.weightRanges = weightRanges
	}
	if cfg.AutoEjectHost && len(cfg.Slaves) > 1 {
		go pool.detectFailureTick()
	}
	return pool
}

Hello, we'll take a look and fix it.