-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 미션 인증 및 완료 사진 업로드 단계 예외케이스 처리 (#114)
* chore: RedisConfig에 RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP 설정 추가 * feat: MissionRecordTTl, Repository 클래스 생성 * chore: RedisExpireEvent 상수 생성 * feat: RedisExpireEventRedisMessageListener 생성 * chore: RedisMessageListenerConfig 생성 * feat: 미션 일지 생성 후 Redis에 TTL 저장 * fix: TTL 10분으로 설정 * style: spotless * refactor: EXPIRATION_TIME 상수 적용과 ttl 변수명 변경
- Loading branch information
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordTTLRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.depromeet.domain.missionRecord.dao; | ||
|
||
import com.depromeet.domain.missionRecord.domain.MissionRecordTTL; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface MissionRecordTTLRepository extends CrudRepository<MissionRecordTTL, Long> {} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/depromeet/domain/missionRecord/domain/MissionRecordTTL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.depromeet.domain.missionRecord.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
@RedisHash("MissionRecordTTL") | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MissionRecordTTL { | ||
@Id private String key; | ||
|
||
@TimeToLive private Long timeToLive; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private MissionRecordTTL(String key, Long timeToLive) { | ||
this.key = key; | ||
this.timeToLive = timeToLive; | ||
} | ||
|
||
public static MissionRecordTTL createMissionRecordTTL(String key, Long timeToLive) { | ||
return MissionRecordTTL.builder().key(key).timeToLive(timeToLive).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...java/com/depromeet/domain/missionRecord/service/RedisExpireEventRedisMessageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.depromeet.domain.missionRecord.service; | ||
|
||
import com.depromeet.domain.missionRecord.dao.MissionRecordRepository; | ||
import com.depromeet.global.common.constants.RedisExpireEventConstants; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class RedisExpireEventRedisMessageListener implements MessageListener { | ||
private final MissionRecordRepository missionRecordRepository; | ||
|
||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
String patternStr = new String(pattern); | ||
log.info( | ||
"RedisExpireEventRedisMessageListener.onMessage : message = {}, pattern = {}", | ||
message.toString(), | ||
patternStr); | ||
if (!patternStr.equals(RedisExpireEventConstants.REDIS_EXPIRE_EVENT_PATTERN.getValue())) { | ||
return; | ||
} | ||
String event = message.toString().split(":")[1]; | ||
|
||
if (!event.startsWith( | ||
RedisExpireEventConstants.EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END.getValue())) { | ||
return; | ||
} | ||
|
||
Long missionRecordId = Long.valueOf(event.split("_")[6]); | ||
missionRecordRepository.deleteById(missionRecordId); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/depromeet/global/common/constants/RedisExpireEventConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.depromeet.global.common.constants; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum RedisExpireEventConstants { | ||
REDIS_EXPIRE_EVENT_PATTERN("__keyevent@*__:expired"), | ||
EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END("EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END_"); | ||
private final String value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/depromeet/infra/config/redis/RedisMessageListenerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.depromeet.infra.config.redis; | ||
|
||
import com.depromeet.domain.missionRecord.service.RedisExpireEventRedisMessageListener; | ||
import com.depromeet.global.common.constants.RedisExpireEventConstants; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.listener.PatternTopic; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
|
||
@Configuration | ||
public class RedisMessageListenerConfig { | ||
@Bean | ||
public RedisMessageListenerContainer redisMessageListenerContainer( | ||
RedisConnectionFactory redisConnectionFactory, | ||
RedisExpireEventRedisMessageListener redisExpireEventRedisMessageListener) { | ||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
container.setConnectionFactory(redisConnectionFactory); | ||
container.addMessageListener( | ||
redisExpireEventRedisMessageListener, | ||
new PatternTopic(RedisExpireEventConstants.REDIS_EXPIRE_EVENT_PATTERN.getValue())); | ||
return container; | ||
} | ||
} |