Skip to content

Commit

Permalink
refactor(RetrieveSetScore): DB에 Redis 캐시를 저장할 때 캐시는 삭제합니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
soeunnPark committed Dec 6, 2024
1 parent b1c4fb4 commit 27a949a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void saveInDb() {
Map<RedisKey, Score> allScores = setRepository.getAllScores();
for (RedisKey key : allScores.keySet()) {
retrieveMatchSet.registerMatchSetScoreInDb(key, allScores.get(key));
retrieveMatchSet.deleteCache(key);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

@Getter
public class RedisKey {
private final String key;
private final String field;
private final MatchType matchType;
private final Long matchId;
private final int setNumber;

public RedisKey(String key, String field) {
this.key = key;
this.field = field;
this.matchType = parseMatchType(key);
this.matchId = parseMatchId(key);
this.setNumber = Integer.parseInt(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public Map<RedisKey, Score> getAllScores() {
}
return scores;
}

public void deleteScore(RedisKey redisKey) {
hashOps.delete(redisKey.getKey(), redisKey.getField());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ public MatchType getMatchType(Long leagueId) {
League league = leagueReader.readLeagueById(leagueId);
return league.getMatchType();
}

public void deleteCache(RedisKey key) {
setRepository.deleteScore(key);
}
}

0 comments on commit 27a949a

Please sign in to comment.