连胜纪录

master
chendian 1 year ago
parent d0a3f92c58
commit 9ceb30d0d7

@ -19,12 +19,20 @@ func init() {
client = redis.NewClient(opts) client = redis.NewClient(opts)
} }
func UpdateReport(appId string, scoreMap map[string]int32) error { func UpdateReport(appId string, report *pb.Report) error {
ctx := context.Background() ctx := context.Background()
pip := client.Pipeline() pip := client.Pipeline()
for openId, score := range scoreMap { keyScore := ThisWeekScoreKey(appId)
key := ThisWeekScoreKey(appId) WinningStreak := WinningStreakKey(appId)
pip.ZIncrBy(ctx, key, float64(score), openId) for _, report := range report.Info {
if report.Score > 0 {
pip.ZIncrBy(ctx, keyScore, float64(report.Score), report.OpenId)
}
if report.IsWin {
pip.ZIncrBy(ctx, WinningStreak, 1, report.OpenId)
} else {
pip.ZRem(ctx, WinningStreak, report.OpenId)
}
} }
_, err := pip.Exec(ctx) _, err := pip.Exec(ctx)
return err return err

@ -13,6 +13,10 @@ func UserDataKey(appId string, openId string) string {
return fmt.Sprintf("UserData_%s_%s", appId, openId) return fmt.Sprintf("UserData_%s_%s", appId, openId)
} }
func WinningStreakKey(appId string) string {
return fmt.Sprintf("WinningStreak_%s", appId)
}
func ThisWeekScoreKey(appId string) string { func ThisWeekScoreKey(appId string) string {
weekStart := getWeekStart(time.Now()) weekStart := getWeekStart(time.Now())
return fmt.Sprintf("Score_%s_%d", appId, weekStart) return fmt.Sprintf("Score_%s_%d", appId, weekStart)

Loading…
Cancel
Save