100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package redisconst
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
visitLogFmt = "bd_visitlog:%s:%d"
|
|
FiveMVisit = "bd_visitFmt:%s"
|
|
BloomUser = "bd_bloom_user:%d"
|
|
AppUserToken = "bd_app_user_token:%d"
|
|
captchaKey = "bd_captcha_mobile_%s"
|
|
CaptchaExpire = 5 * time.Minute
|
|
replayNonceKey = "bd_replay:nonce:_%s"
|
|
mediaM3U8Fmt = "m3u8cache:%s"
|
|
MediaM3U8CacheExpire = time.Hour * 24 * 7
|
|
|
|
//禁止登陆设置
|
|
userForbit = "userForbit:%d"
|
|
ipForbit = "ipForbit:%s"
|
|
|
|
//每分钟Ip注册次数
|
|
registerLimist = "registerLimit:%s"
|
|
RegisterLimistExpire = time.Minute * 30
|
|
|
|
//用户关注限制
|
|
careLimitKey = "carelimit:%d"
|
|
CareLimitKeyExpire = 15 * time.Second
|
|
|
|
//用户评论限制
|
|
commentLimitKey = "commentlimit:%s"
|
|
CommentLimitKeyExpire = 1 * time.Minute
|
|
CommentDayLimitKeyExpire = 10 * time.Hour
|
|
|
|
//每用户访问次数限制
|
|
userCallLimit = "userCall:%d"
|
|
ipCallLimit = "ipCall:%s"
|
|
CallLimitExpire = time.Second * 10
|
|
)
|
|
|
|
func BloomUserKey(userId int64) string {
|
|
return fmt.Sprintf(BloomUser, userId)
|
|
}
|
|
|
|
func FiveMVisitKey(time string) string {
|
|
return fmt.Sprintf(FiveMVisit, time)
|
|
}
|
|
|
|
func UserVisitLogKey(uid int64, t time.Time) string {
|
|
return fmt.Sprintf(visitLogFmt, t.Format("20060102"), uid)
|
|
}
|
|
|
|
func MobileCaptchaKey(mobile string) string {
|
|
return fmt.Sprintf(captchaKey, mobile)
|
|
}
|
|
|
|
func AppUserTokenKey(userId int64) string {
|
|
return fmt.Sprintf(AppUserToken, userId)
|
|
}
|
|
|
|
func MediaM3U8Key(name string) string {
|
|
return fmt.Sprintf(mediaM3U8Fmt, name)
|
|
}
|
|
func UserForbitKey(userId int64) string {
|
|
return fmt.Sprintf(userForbit, userId)
|
|
}
|
|
|
|
func RegisterLimitKey(ip string) string {
|
|
ip = strings.ReplaceAll(ip, ":", "-")
|
|
return fmt.Sprintf(registerLimist, ip)
|
|
}
|
|
|
|
func CareLimitKey(userId int64) string {
|
|
return fmt.Sprintf(careLimitKey, userId)
|
|
}
|
|
func ReplayNonceKey(nonce string) string {
|
|
return fmt.Sprintf(replayNonceKey, nonce)
|
|
}
|
|
|
|
func CommentLimitKey(ip string) string {
|
|
return fmt.Sprintf(commentLimitKey, ip)
|
|
}
|
|
func CommentOneDayLimitKey(ip string) string {
|
|
return fmt.Sprintf("commentdaylimit:%s", ip)
|
|
}
|
|
|
|
func UserCallLimitKey(userId int64) string {
|
|
return fmt.Sprintf(userCallLimit, userId)
|
|
}
|
|
|
|
func IpCallLimitKey(ip string) string {
|
|
return fmt.Sprintf(ipCallLimit, ip)
|
|
}
|
|
|
|
func IpForbitKey(ip string) string {
|
|
ip = strings.ReplaceAll(ip, ":", "-")
|
|
return fmt.Sprintf(ipForbit, ip)
|
|
} |