Beispiel #1
0
func GetInfos(category, key string) *myredis.TagsInfo {
	//first get awsinfo from redis
	m := myredis.HMget(key)

	if m != nil {
		//if redis not find the key,then get awsinfo from aws
		if m.Name == "" || m.Region == "" || m.Id == "" {
			if category == "ip" {
				Update("ip", key)
			} else {
				Update("id", key)
			}
			m = myredis.HMget(key)
		}
		return m
	}

	//maybe redis server down
	v, ok := memMap[key]
	if ok {
		m = v
	} else {
		if category == "ip" {
			Update("ip", key)
		} else {
			Update("id", key)
		}
		m = memMap[key]
	}
	return m
}
//sync the infos from aws to redis,then sync the infos to memory cache:memMap
func SyncInfos() {
	go func() {
		tick := time.Tick(time.Duration(g.Config().UpdateStep) * time.Second)
		for _ = range tick {
			ks := myredis.GetKeys()
			for i := 0; i < len(ks); i++ {
				k := ks[i]
				m := myredis.HMget(k)
				id := m.Id
				funcs.Update("id", id)
			}
		}
	}()
}