Skip to content

Commit

Permalink
add redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Eundms committed Jun 29, 2023
1 parent 97e01fb commit 34f80a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
<version>4.0.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>3.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mindrot/jbcrypt -->
<dependency>
<groupId>org.mindrot</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/team08/enjoytrip/EnjoytripApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@EnableCaching
@SpringBootApplication
public class EnjoytripApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -82,6 +84,8 @@ public ResponseEntity<ResponseDto> modifyArticle(@PathVariable int articleId, @R
postService.modifyArticle(postDto);
return new ResponseEntity<>(new ResponseDto("글 수정", null), HttpStatus.OK);
}

@Cacheable(value="post-single", key="#articleId")
@GetMapping("/{articleId}")
public ResponseEntity<ResponseDto> searchArticle(@PathVariable int articleId) {
log.debug("[GET] /articles/{articleId} : " + articleId);
Expand All @@ -91,6 +95,7 @@ public ResponseEntity<ResponseDto> searchArticle(@PathVariable int articleId) {
return new ResponseEntity<>(new ResponseDto("특정 글 조회", articleDto), HttpStatus.OK);
}

@CacheEvict(value="post-single",key="#articleId")
@DeleteMapping("/{articleId}")
public ResponseEntity<ResponseDto> deleteArticle(@PathVariable int articleId) {
log.debug("[DELETE] /articles/{articleId} : " + articleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.team08.enjoytrip.tripRoute.model.service.TripRouteService;
import com.team08.enjoytrip.user.model.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -41,7 +42,7 @@ public ResponseEntity<ResponseDto> getLikeRoute(@PathVariable int routeId) {
return new ResponseEntity<>(new ResponseDto("route favorite 완료", null), HttpStatus.OK);
}


@Cacheable(value="route-multi", key="#id")
@GetMapping("/{id}")
public ResponseEntity<ResponseDto> get(@PathVariable int id) {
log.debug("[GET] /trip-routes/" + id);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ logging.level.com.team08.enjoytrip = debug
# window
file.path=C:/board/upload/
file.path.upload-files=C:/board/upload/fileUpload/


# Redis ?? ??
spring.cache.type = redis
spring.redis.host = localhost
spring.redis.port = 6379

0 comments on commit 34f80a0

Please sign in to comment.