From 5d00d8df55c3f39358a132e586b6540af3a23e87 Mon Sep 17 00:00:00 2001 From: Donaldson Date: Fri, 10 Dec 2021 16:13:34 -0800 Subject: [PATCH] Mostly working, now --- cmd/mothd/main.go | 2 ++ cmd/mothd/redis_state.go | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/mothd/main.go b/cmd/mothd/main.go index e238bac..847b191 100644 --- a/cmd/mothd/main.go +++ b/cmd/mothd/main.go @@ -97,6 +97,7 @@ func main() { switch engine := *stateEngine; engine { case "redis": + log.Println("Moth is running with Redis") redis_url_parsed := *redis_url if redis_url_parsed == "" { redis_url_parsed = os.Getenv("REDIS_URL") @@ -126,6 +127,7 @@ func main() { state = NewRedisState(redis_url_parsed, int(redis_db_parsed), redis_instance_id_parsed) default: case "legacy": + log.Println("Moth is running with the legacy state engine") state = NewState(afero.NewBasePathFs(osfs, *statePath)) } diff --git a/cmd/mothd/redis_state.go b/cmd/mothd/redis_state.go index 55e2a3c..29c66c0 100644 --- a/cmd/mothd/redis_state.go +++ b/cmd/mothd/redis_state.go @@ -131,9 +131,16 @@ func (s *RedisState) SetTeamName(teamID, teamName string) error { return fmt.Errorf("team ID: (%s) not found in list of valid team IDs", teamID) } - success, err := s.redis_client.HSetNX(s.ctx, s.formatRedisKey(REDIS_KEY_TEAM_IDS), teamID, teamName).Result() + exists, err := s.redis_client.HExists(s.ctx, s.formatRedisKey(REDIS_KEY_TEAMS), teamID).Result() + + if exists { + return nil + } + + success, err := s.redis_client.HSetNX(s.ctx, s.formatRedisKey(REDIS_KEY_TEAMS), teamID, teamName).Result() if err != nil { + fmt.Println(err) return fmt.Errorf("Unexpected error while setting team ID: %s and team Name: %s", teamID, teamName) } @@ -148,12 +155,13 @@ func (s *RedisState) SetTeamName(teamID, teamName string) error { // PointsLog retrieves the current points log. func (s *RedisState) PointsLog() award.List { redis_args := &redis.ZRangeBy{ - Min: "0", - Max: "-1", + Min: "-inf", + Max: "+inf", } scores, err := s.redis_client.ZRangeByScoreWithScores(s.ctx, s.formatRedisKey(REDIS_KEY_POINT_LOG), redis_args).Result() if err != nil { + fmt.Println("Encountered an error processing points") return make(award.List, 0) }