Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 3000
appendonly yes
stop-writes-on-bgsave-error no
maxmemory-policy allkeys-lru
maxmemory 1gb
38 changes: 38 additions & 0 deletions infrastructure/redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
/src/main/generated/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
21 changes: 21 additions & 0 deletions infrastructure/redis/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

//lombok
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor("org.mapstruct:mapstruct-processor:1.5.3.Final")
// redis client
implementation 'org.redisson:redisson-spring-boot-starter:3.29.0'
implementation 'it.ozimov:embedded-redis:0.7.2'
testImplementation 'it.ozimov:embedded-redis:0.7.2'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
testImplementation 'org.springframework.boot:spring-boot-starter-data-redis'
}

tasks.register("prepareKotlinBuildScriptModel"){}
Binary file not shown.
7 changes: 7 additions & 0 deletions infrastructure/redis/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.ecommerce.redis.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.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@EnableRedisRepositories
public class LettuceSingleConfig {

@Value("${spring.data.redis.host}")
private String redisHost;

@Value("${spring.data.redis.port}")
private int redisPort;

@Bean
public RedisConnectionFactory redisConnectionFactory(){
return new LettuceConnectionFactory(redisHost,redisPort);
}

@Bean
public RedisTemplate<String, Object> redisTemplate(){
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();

redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());

redisTemplate.setDefaultSerializer(new StringRedisSerializer());

redisTemplate.setConnectionFactory(redisConnectionFactory());
return redisTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ecommerce.paymentapi.config;
package org.ecommerce.redis.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
Expand All @@ -10,7 +10,7 @@
@Getter
@Setter
@ConfigurationProperties(prefix = "spring.data.redis")
public class RedisProperties {
public class RedisSingleInfo {
private String host;
private int port;
private String REDISSON_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
package org.ecommerce.paymentapi.config;
package org.ecommerce.redis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.RequiredArgsConstructor;

/*
* RedissonClient Configuration
*/
@RequiredArgsConstructor
@Configuration
public class RedissonConfig {

private final RedisProperties redisProperties;
public class RedissonSingleConfig {
private final RedisSingleInfo redisSingleInfo;

@Bean
public RedissonClient redissonClient() {
RedissonClient redisson = null;
Config config = new Config();
config.useSingleServer().setAddress(redisProperties.getREDISSON_PREFIX() + redisProperties.getHost() +
":" + redisProperties.getPort());
config.useSingleServer().setAddress(redisSingleInfo.getREDISSON_PREFIX() + redisSingleInfo.getHost() +
":" + redisSingleInfo.getPort());
redisson = Redisson.create(config);
return redisson;
}
Expand Down
12 changes: 12 additions & 0 deletions infrastructure/redis/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring :
application :
name: redis
data:
redis:
host: localhost
port: 6379
redisson-prefix: "redis://"




1 change: 1 addition & 0 deletions payment-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repositories {

dependencies {
implementation(project(':common'))
implementation(project(':infrastructure:redis'))

//공통 모듈
implementation 'org.springframework.boot:spring-boot-starter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@EnableFeignClients
@SpringBootApplication(scanBasePackages = {
"org.ecommerce.common",
"org.ecommerce.paymentapi"
"org.ecommerce.paymentapi",
"org.ecommerce.redis"
}, nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class)
public class PaymentApiApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
@Slf4j
public class DistributedLockAop {
private static final String REDISSON_LOCK_PREFIX = "LOCK";

private final RedissonClient redissonClient;
private final AopForTransaction aopForTransaction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@Table(name = "payment_detail",
indexes = {
@Index(name = "idx_order_item_id", columnList = "orderItemId"),
@Index(name = "idx_create_datetime", columnList = "createDateTime"),
@Index(name = "idx_create_datetime", columnList = "createDatetime"),
}
)
public class PaymentDetail {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Table(
name = "seller_beanpay",
indexes = {
@Index(name = "idx_seller_id", columnList = "userId"),
@Index(name = "idx_seller_id", columnList = "sellerId"),
})
public class SellerBeanPay {

Expand Down
3 changes: 2 additions & 1 deletion payment-api/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ spring:
mode: always
data:
redis:
host: 127.0.0.1
host: localhost
port: 6379
redisson-prefix: "redis://"

toss:
secretKey: test
server:
Expand Down
3 changes: 2 additions & 1 deletion payment-api/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ spring:
mode: never
data:
redis:
host: 127.0.0.1
host: localhost
port: 16379
redisson-prefix: "redis://"

toss:
secretKey: test
server:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package org.ecommerce.paymentapi.config;

import org.ecommerce.redis.config.RedisSingleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import redis.embedded.Redis;
import redis.embedded.RedisServer;

@Configuration
public class LocalRedisConfig{

private final RedisProperties redisProperties;

private final RedisServer redisServer;

private RedisSingleInfo redisSingleInfo;
private Redis redisServer;

@Autowired
public LocalRedisConfig(RedisProperties properties) {
this.redisProperties = properties;
this.redisServer = new RedisServer(redisProperties.getPort());
public LocalRedisConfig(RedisSingleInfo redisSingleInfo) {
this.redisSingleInfo = redisSingleInfo;
this.redisServer = new RedisServer(redisSingleInfo.getPort());
}

@PostConstruct
Expand Down
16 changes: 16 additions & 0 deletions redis-single.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 파일 규격 버전
version: "3.1"

# 실행하려는 컨테이너들 정의
services:
redis_container:
image: redis:7.0.0
volumes:
- ./config/redis.conf:/etc/redis.conf
restart: always
ports:
- "6379:6379"
labels:
- "name=redis"
- "mode=standalone"
command: redis-server /etc/redis.conf
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ include 'order-api'
include 'payment-api'
include 'product-api'
include 'statistic-api'
include 'common'
include 'common'
include 'infrastructure:redis'