package util import ( MC "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" "fmt" IC "jyBXCore/rpc/init" ) var SearchLimitKey = "jy_limitSearchText_new" var SearchLimitFlag = "jy_limitSearchText_%s" // func IsSearchLimit(searchItems []string) bool { for _, searchItem := range searchItems { if searchItem == "detail" || searchItem == "filetext" { return true } } return false } // func LimitSearchInit() { if IC.C.LimitSearchText.Flag { LimitSearchClear() for i := 0; i < IC.C.LimitSearchText.Count; i++ { redis.RPUSH("other", SearchLimitKey, 1) } } } // func LimitSearchClear() { redis.Del("other", SearchLimitKey) } //限制正文、附件查询 //return 1 正常 //return -1 抱歉!由于系统繁忙暂时无法进行搜索,请1分钟后再试! //return -2 抱歉!由于系统繁忙暂时无法进行搜索,请稍后再试! func IsLimited(userId string, isPayedUser bool) int64 { if !IC.C.LimitSearchText.Flag { return 1 } var llen = int(redis.LLEN("other", SearchLimitKey)) if IC.C.LimitSearchText.TimeOut > 0 { if llen <= IC.C.LimitSearchText.Count/2 { timeLimit, _ := redis.Exists("other", fmt.Sprintf(SearchLimitFlag, userId)) if timeLimit { return -1 } } redis.Put("other", fmt.Sprintf(SearchLimitFlag, userId), 1, IC.C.LimitSearchText.TimeOut) } if IC.C.LimitSearchText.Count == -2 { //不限制 return 1 } else if IC.C.LimitSearchText.Count == -1 { //无条件限制 return -2 } //免费和付费用户 使用并发的80%(默认)通道|| 保留一条通道给付费用户使用 if !isPayedUser { if llen <= IC.C.LimitSearchText.Count*IC.C.LimitSearchText.Percentage/100 || llen == 1 { return -1 } } // pollLimit := redis.LPOP("other", SearchLimitKey) if MC.IntAll(pollLimit) <= 0 { return -2 } return 1 } // func Limit() { if !IC.C.LimitSearchText.Flag { return } if int(redis.LLEN("other", SearchLimitKey)) < IC.C.LimitSearchText.Count { redis.RPUSH("other", SearchLimitKey, 1) } } // func IsCanLogin(userId string) bool { for _, v := range IC.C.LimitSearchText.UserIds { if v == userId { return true } } return false }