示例#1
0
func (self *RedisCluster) disconnectAll() {
	if self.Debug {
		log.Info("[RedisCluster] PID:", os.Getpid(), " [Disconnect!] Had Handles:", self.Handles.Count())
	}
	// disconnect anyone in handles
	// for _, handle := range self.Handles {
	for item := range self.Handles.Iter() {
		item.Val.(*RedisHandle).Pool.Close()
	}
	// nuke handles
	//for addr, _ := range self.SeedHosts {
	for item := range self.SeedHosts.Iter() {
		// delete(self.Handles, item.Key)
		self.Handles.Remove(item.Key)
	}
	// nuke slots
	self.Slots = iMap.New()
}
示例#2
0
func NewRedisCluster(seed_redii []map[string]string, poolConfig PoolConfig, debug bool) RedisCluster {
	cluster := RedisCluster{
		RefreshTableASAP: false,
		SingleRedisMode:  !poolConfig.IsCluster,
		SeedHosts:        cmap.New(), //make(map[string]bool),
		Handles:          cmap.New(), //make(map[string]*RedisHandle),
		Slots:            iMap.New(), // make(map[uint16]string),
		poolConfig:       poolConfig,
		Debug:            debug,
	}

	if cluster.Debug {
		log.Debug("[RedisCluster], PID", os.Getpid(), "StartingNewRedisCluster")
	}

	for _, redis := range seed_redii {
		for host, port := range redis {
			label := host + ":" + port
			cluster.SeedHosts.Set(label, true)
			cluster.Handles.Set(label, NewRedisHandle(host, port, poolConfig, debug))
		}
	}

	//for addr, _ := range cluster.SeedHosts {
	for item := range cluster.SeedHosts.Iter() {
		node := cluster.addRedisHandleIfNeeded(item.Key)
		cluster_enabled := cluster.hasClusterEnabled(node)
		if cluster_enabled == false {
			if cluster.SeedHosts.Count() == 1 {
				cluster.SingleRedisMode = true
			} else {
				log.Fatal(errors.New("Multiple Seed Hosts Given, But Cluster Support Disabled in Redis"))
			}
		}
	}

	if cluster.SingleRedisMode == false {
		cluster.populateSlotsCache()
	}
	return cluster
}