Esempio n. 1
0
File: loader.go Progetto: 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()
	}
}
Esempio n. 2
0
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)
}