-
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: redis 동작 확인을 위한 테스트 api를 추가한다.
- Loading branch information
Showing
4 changed files
with
50 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: cd-dev-docker | |
|
||
on: | ||
push: | ||
branches: [ "dev" ] | ||
branches: [ "dev", "feat/#298" ] | ||
|
||
jobs: | ||
build: | ||
|
25 changes: 12 additions & 13 deletions
25
src/main/java/com/clova/anifriends/global/config/RedisConfig.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 |
---|---|---|
@@ -1,39 +1,38 @@ | ||
package com.clova.anifriends.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@EnableCaching | ||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.redis.host}") | ||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.redis.port}") | ||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
// @Bean | ||
// public RedisTemplate<String, Integer> redisTemplate() { | ||
// RedisTemplate<String, Integer> redisTemplate = new RedisTemplate<>(); | ||
// redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
// redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
// redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
// return redisTemplate; | ||
// } | ||
|
||
@Bean | ||
public RedisTemplate<?, ?> redisTemplate() { | ||
RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>(); | ||
public RedisTemplate<String, Integer> redisTemplate() { | ||
RedisTemplate<String, Integer> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
return redisTemplate; | ||
} | ||
} | ||
|
||
|
||
|
Submodule backend-config
updated
from 313b0a to 7dcc9f
36 changes: 36 additions & 0 deletions
36
src/test/java/com/clova/anifriends/global/RedisTestController.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,36 @@ | ||
package com.clova.anifriends.global; | ||
|
||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class RedisTestController { | ||
|
||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
@PostMapping("/data") | ||
public ResponseEntity<String> setRedisData( | ||
@RequestBody(required = true) Map<String, String> map) throws Exception { | ||
|
||
redisTemplate.opsForValue().set(map.get("key"), map.get("value")); | ||
|
||
return new ResponseEntity<>("정상 등록", HttpStatus.CREATED); | ||
} | ||
|
||
@GetMapping("/data") | ||
public ResponseEntity<String> getRedisData( | ||
@RequestParam(required = true) String key) { | ||
|
||
return new ResponseEntity<>(redisTemplate.opsForValue().get(key), HttpStatus.OK); | ||
|
||
} | ||
} |