-
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
8 changed files
with
82 additions
and
27 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: | ||
|
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
27 changes: 12 additions & 15 deletions
27
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,36 @@ | ||
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.GenericToStringSerializer; | ||
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<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
return redisTemplate; | ||
public RedisTemplate<String, Integer> redisTemplate(RedisConnectionFactory connectionFactory) { | ||
RedisTemplate<String, Integer> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(connectionFactory); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setValueSerializer(new GenericToStringSerializer<>(Integer.class)); | ||
return template; | ||
} | ||
} |
Submodule backend-config
updated
from 313b0a to 7dcc9f
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
28 changes: 28 additions & 0 deletions
28
src/test/java/com/clova/anifriends/base/config/RedisTestContainerConfig.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,28 @@ | ||
package com.clova.anifriends.base.config; | ||
|
||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
public class RedisTestContainerConfig { | ||
|
||
private static final String REDIS_IMAGE = "redis:7.0.8-alpine"; | ||
private static final int REDIS_PORT = 6379; | ||
private static final GenericContainer REDIS_CONTAINER; | ||
|
||
static { | ||
REDIS_CONTAINER = new GenericContainer(REDIS_IMAGE) | ||
.withExposedPorts(REDIS_PORT) | ||
.withReuse(true); | ||
REDIS_CONTAINER.start(); | ||
} | ||
|
||
@DynamicPropertySource | ||
private static void registerRedisProperties(DynamicPropertyRegistry registry) { | ||
registry.add("spring.data.redis.host", REDIS_CONTAINER::getHost); | ||
registry.add("spring.data.redis.port", () -> REDIS_CONTAINER.getMappedPort(REDIS_PORT) | ||
.toString()); | ||
} | ||
} |
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