-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from Prography-8th-team8/refactor-store-id
redis 부착 성능개선
- Loading branch information
Showing
18 changed files
with
175 additions
and
7 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 |
---|---|---|
|
@@ -35,3 +35,6 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### DATA ### | ||
data |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: "3" | ||
|
||
services: | ||
redis: | ||
image: redis:6 | ||
volumes: | ||
- ./data/redis:/data | ||
command: redis-server --port 6379 | ||
ports: | ||
- "6379:6379" | ||
networks: | ||
- cakk | ||
|
||
networks: | ||
cakk: | ||
labels: | ||
- cakk |
36 changes: 36 additions & 0 deletions
36
src/main/java/prography/cakeke/server/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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package prography.cakeke.server.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
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.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private Long port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(); | ||
configuration.setHostName(host); | ||
configuration.setPort(port.intValue()); | ||
return new LettuceConnectionFactory(configuration); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<?, ?> redisTemplate() { | ||
RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
return redisTemplate; | ||
} | ||
} |
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
Empty file.
2 changes: 1 addition & 1 deletion
2
...re/application/port/out/UploadS3Port.java → ...ge/application/port/out/UploadS3Port.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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/prography/cakeke/server/store/adapter/out/external/RedisAdapter.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,35 @@ | ||
package prography.cakeke.server.store.adapter.out.external; | ||
|
||
import java.time.Duration; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import prography.cakeke.server.store.application.port.out.LoadRedisPort; | ||
import prography.cakeke.server.store.application.port.out.SaveRedisPort; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class RedisAdapter implements LoadRedisPort, SaveRedisPort { | ||
private final RedisTemplate<String, String> redisTemplate; | ||
private final Integer TTL = 86400; | ||
|
||
@Override | ||
public String save(String key, String value) { | ||
getOperations().set(key, value, Duration.ofMillis(TTL)); | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getByKey(String key) { | ||
return getOperations().get(key); | ||
} | ||
|
||
private ValueOperations<String, String> getOperations() { | ||
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(String.class)); | ||
return redisTemplate.opsForValue(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/prography/cakeke/server/store/application/port/out/LoadRedisPort.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 prography.cakeke.server.store.application.port.out; | ||
|
||
public interface LoadRedisPort { | ||
String getByKey(String key); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/prography/cakeke/server/store/application/port/out/SaveRedisPort.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 prography.cakeke.server.store.application.port.out; | ||
|
||
public interface SaveRedisPort { | ||
String save(String key, 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
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
26 changes: 26 additions & 0 deletions
26
src/test/java/prography/cakeke/server/config/RedisTestContainers.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 prography.cakeke.server.config; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@DisplayName("Redis Test Containers") | ||
@Configuration | ||
public class RedisTestContainers { | ||
|
||
private static final String REDIS_DOCKER_IMAGE = "redis:5.0.3-alpine"; | ||
|
||
static { // (1) | ||
GenericContainer<?> REDIS_CONTAINER = | ||
new GenericContainer<>(DockerImageName.parse(REDIS_DOCKER_IMAGE)) | ||
.withExposedPorts(6379) | ||
.withReuse(true); | ||
|
||
REDIS_CONTAINER.start(); // (2) | ||
|
||
// (3) | ||
System.setProperty("spring.data.redis.host", REDIS_CONTAINER.getHost()); | ||
System.setProperty("spring.data.redis.port", REDIS_CONTAINER.getMappedPort(6379).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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: "3" | ||
|
||
services: | ||
redis: | ||
image: redis:7 | ||
command: redis-server --port 6379 | ||
ports: | ||
- "6380:6379" |