-
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.
feat(store): store id 조회를 redis에 cache처리
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 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 |
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