-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(HotBoards): 인기 게시글 저장에 Redis를 사용하도록 변경
- Loading branch information
1 parent
2560a09
commit 901ee99
Showing
9 changed files
with
96 additions
and
19 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
...b/api/domain/community/board/adapter/out/persistence/RedisHotBoardPersistenceAdapter.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,38 @@ | ||
package page.clab.api.domain.community.board.adapter.out.persistence; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
import page.clab.api.domain.community.board.application.port.out.RegisterHotBoardPort; | ||
import page.clab.api.domain.community.board.application.port.out.RemoveHotBoardPort; | ||
import page.clab.api.domain.community.board.application.port.out.RetrieveHotBoardPort; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RedisHotBoardPersistenceAdapter implements | ||
RegisterHotBoardPort, | ||
RetrieveHotBoardPort, | ||
RemoveHotBoardPort { | ||
|
||
private static final String HOT_BOARDS_KEY = "hotBoards"; | ||
|
||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
@Override | ||
public void save(String boardId) { | ||
redisTemplate.opsForList().rightPush(HOT_BOARDS_KEY, boardId); | ||
} | ||
|
||
@Override | ||
public List<String> findAll() { | ||
List<String> hotBoards = redisTemplate.opsForList().range(HOT_BOARDS_KEY, 0, -1); | ||
return (hotBoards != null) ? hotBoards : List.of(); | ||
} | ||
|
||
@Override | ||
public void clearHotBoard() { | ||
redisTemplate.delete(HOT_BOARDS_KEY); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
.../java/page/clab/api/domain/community/board/application/port/out/RegisterHotBoardPort.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,5 @@ | ||
package page.clab.api.domain.community.board.application.port.out; | ||
|
||
public interface RegisterHotBoardPort { | ||
void save(String boardId); | ||
} |
5 changes: 5 additions & 0 deletions
5
...in/java/page/clab/api/domain/community/board/application/port/out/RemoveHotBoardPort.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,5 @@ | ||
package page.clab.api.domain.community.board.application.port.out; | ||
|
||
public interface RemoveHotBoardPort { | ||
void clearHotBoard(); | ||
} |
7 changes: 7 additions & 0 deletions
7
.../java/page/clab/api/domain/community/board/application/port/out/RetrieveHotBoardPort.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,7 @@ | ||
package page.clab.api.domain.community.board.application.port.out; | ||
|
||
import java.util.List; | ||
|
||
public interface RetrieveHotBoardPort { | ||
List<String> findAll(); | ||
} |
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
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
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