You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
798 B
Go

1 year ago
package redis
import (
"fmt"
"time"
)
func PublishKey(appId string, roomId string) string {
return fmt.Sprintf("DataPush_%s_%s", appId, roomId)
}
func UserDataKey(appId string, openId string) string {
return fmt.Sprintf("UserData_%s_%s", appId, openId)
}
func ThisWeekScoreKey(appId string) string {
weekStart := getWeekStart(time.Now())
return fmt.Sprintf("Score_%s_%d", appId, weekStart)
}
func LastWeekScoreKey(appId string) string {
weekStart := getWeekStart(time.Now().Add(-time.Hour * 24 * 7))
return fmt.Sprintf("Score_%s_%d", appId, weekStart)
}
func getWeekStart(now time.Time) int64 {
startOfWeek := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
startOfWeek = startOfWeek.AddDate(0, 0, int(-startOfWeek.Weekday()))
return startOfWeek.Unix()
}