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.
35 lines
893 B
Go
35 lines
893 B
Go
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 WinningStreakKey(appId string) string {
|
|
return fmt.Sprintf("WinningStreak_%s", appId)
|
|
}
|
|
|
|
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()
|
|
}
|