1616public class RedisService { // TODO: RedisReportService 로 변경.
1717
1818 private final RedisTemplate <String , String > redisTemplate ;
19-
19+ private static final String ADMIN_ALARM_KEY = "ADMIN_ALARM" ;
2020 private static final int ADMIN_LOGIN_MAX_REQUESTS =10 ;
2121 private static final int MAX_REQUESTS = 3 ; // 제한 횟수 (기본값: 5분 동안 3회)
2222 private static final long EXPIRED_TIME = 5L ; // 만료 시간 (5분)
@@ -63,8 +63,8 @@ public boolean isAdminLoginAllowed(String category,String identifier){
6363 String redisKey = getRateLimitKey (category , identifier );
6464 String requestCountStr = redisTemplate .opsForValue ().get (redisKey );
6565 int requestCount = requestCountStr == null ? 0 : Integer .parseInt (requestCountStr );
66-
67- if (requestCount >= ADMIN_LOGIN_MAX_REQUESTS ) {
66+ requestCount += 1 ;
67+ if (0 >=( ADMIN_LOGIN_MAX_REQUESTS - requestCount ) ) {
6868 log .warn ("🚫 [RateLimit] 관리자 요청 차단 - Key: {}, 요청 횟수: {}" , redisKey , requestCount );
6969 return false ;
7070 }
@@ -75,7 +75,6 @@ public boolean isAdminLoginAllowed(String category,String identifier){
7575 return true ;
7676
7777 }
78-
7978 public boolean AdminReadCheck (String category , String adminIdentifier , StaticDataType staticDataType , Long contentId ){
8079
8180 String redisKey =getRateLimitKey (category ,adminIdentifier +staticDataType .name ()+String .valueOf (contentId ));
@@ -96,8 +95,24 @@ public void adminReadCheckUpdate(String category, String adminIdentifier, Static
9695 redisTemplate .expire (redisKey , Duration .ofMinutes (ADMIN_ALARM_READ_EXPIRE_TIME ));
9796 }
9897 }
99-
100-
98+ /*public boolean AdminReadCheck(String adminIdentifier, StaticDataType staticDataType, Long contentId){
99+ String redisKey=ADMIN_ALARM_KEY+adminIdentifier+staticDataType.name()+String.valueOf(contentId);
100+ String requestCountStr=redisTemplate.opsForValue().get(redisKey);
101+ int requestCount = requestCountStr == null ? 0 : Integer.parseInt(requestCountStr);
102+ if(requestCount==0){
103+ return false;
104+ }
105+ return true;
106+ }
107+ public void adminReadCheckUpdate(String adminIdentifier, StaticDataType staticDataType, Long contentId){
108+ String redisKey=ADMIN_ALARM_KEY+adminIdentifier+staticDataType.name()+String.valueOf(contentId);
109+ String requestCountStr=redisTemplate.opsForValue().get(redisKey);
110+ int requestCount = requestCountStr == null ? 0 : Integer.parseInt(requestCountStr);
111+ if(requestCount==0) {
112+ redisTemplate.opsForValue().increment(redisKey);
113+ redisTemplate.expire(redisKey, Duration.ofDays(30L));
114+ }
115+ }*/
101116 /**
102117 * 요청 제한을 적용할 Redis Key 생성
103118 *
0 commit comments