Files
2026-05-20 16:13:58 +08:00

74 lines
2.5 KiB
Go

package redis
import (
"fmt"
"time"
)
const (
AdvertiseClickDayHashTemplate = "stat-center.advertise.day.click.%s" // 广告点击
AdvertiseClickDayHashIdHourSep = "@"
IpLimiterKeyTemplate = "stat-center.%s:%d.ip.limiter.key#%s"
IpLimiterDayRecordKey = "stat-center.ip.limiter.day.record.key"
DownloadCheckBotMsgHashKeyTmpl = "stat-center.download.check.bot.msg.hash.key.%s" // 下载提示消息
ServerStartTimeHashKeyTemplate = "stat-center.server.start_time.hash.key.%d"
ServerKeepAliveHashKeyTemplate = "stat-center.server.keepalive.hash.key.%d"
ServerCloseFlagHashKeyTemplate = "stat-center.server.close.flag.hash.key.%d"
)
func GetServerStartTimeHashKey(index int) string {
return fmt.Sprintf(ServerStartTimeHashKeyTemplate, index)
}
func GetServerKeepAliveHashKey(index int) string {
return fmt.Sprintf(ServerKeepAliveHashKeyTemplate, index)
}
func GetServerCloseFlagHashKey(index int) string {
return fmt.Sprintf(ServerCloseFlagHashKeyTemplate, index)
}
func GetDownloadCheckBotMsgHashKey() string {
return fmt.Sprintf(DownloadCheckBotMsgHashKeyTmpl, time.Now().Format("2006-02-01-15"))
}
func GetIpLimitDayKey(serverIp string, serverPort int) string {
ts := time.Now().Local().Format("2006-02-01")
return fmt.Sprintf(IpLimiterKeyTemplate, serverIp, serverPort, ts)
}
func GetIpLimitSpecifiedDayKey(serverIp string, serverPort int, day time.Time) string {
ts := day.Local().Format("2006-02-01")
return fmt.Sprintf(IpLimiterKeyTemplate, serverIp, serverPort, ts)
}
func GetAdvertiseClickDayHash(now time.Time) *Hash {
t := now.Local().Format("2006-02-01")
return NewHash(StatRds.Client(), fmt.Sprintf(AdvertiseClickDayHashTemplate, t))
}
func GetAdvertiseClickHourName(appId int32, adsId int64, hour int) string {
return fmt.Sprintf("%d%s%d%s%d", appId, AdvertiseClickDayHashIdHourSep, adsId, AdvertiseClickDayHashIdHourSep, hour)
}
const (
NameSource = "name:source" //姓名池
NameSourceExpire = 2 * 24 * time.Hour
AppClickDaySetTemplate = "nh.app.day.click.%s" // app点击
AppClickDaySetIdHourSep = "@"
)
func GetAppClickDaySet(now time.Time) *Hash {
t := now.Local().Format("2006-02-01")
return NewHash(StatRds.Client(), fmt.Sprintf(AppClickDaySetTemplate, t))
}
func GetAppClickHourName(appId string, hour int) string {
return fmt.Sprintf("%s%s%d", appId, AppClickDaySetIdHourSep, hour)
}
func GetAppClickHourNameByAppId(appId int64, parentAppId int64, hour int) string {
return fmt.Sprintf("%s_%s%s%d", appId, parentAppId, AppClickDaySetIdHourSep, hour)
}