예제 #1
0
파일: loader.go 프로젝트: yilee/mane
func watch() {
	redis := myredis.DefaultClient()
	for {
		result, err := redis.BLPop(time.Duration(0), EventQueue).Result()
		if err != nil || len(result) != 2 || result[1] != EventQueue {
			//something wrong and watch again!
			continue
		}
		hole <- time.Now().UnixNano()
	}
}
예제 #2
0
파일: rate_limit.go 프로젝트: yilee/mane
func (f *RateLimitFilter) Allow(phone string, template t.Name) bool {
	strategy, existed := f.Strategies[template]
	if !existed {
		return true
	}
	expiration := int64(strategy.Duration * time.Minute / time.Second)
	if !util.IsProduction() {
		//ignore actual setting in non-production environment
		expiration = int64(5 * time.Minute / time.Second)
	}
	redisClient := myredis.DefaultClient()
	res, err := redisClient.Eval(Check, []string{"cnt_" + phone + "_" + string(template)}, []string{strconv.FormatInt(expiration, 10)}).Result()
	if err != nil {
		//FIXME should allow or discard when check failed?
		log.Error.Printf("occur error when check allowed: %v\n", err)
		return false
	}
	return res.(int64) <= int64(strategy.Count)
}