Skip to content

Commit

Permalink
feat-be: Redis 로컬 환경 설정 (#822)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: cutehumanS2 <[email protected]>
Co-authored-by: Kwoun Ki Ho <[email protected]>
  • Loading branch information
3 people authored Oct 19, 2024
1 parent 575877b commit 10c5073
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/be-cd_dev-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ jobs:
COOKIE_PATH=${{ secrets.COOKIE_PATH }}
COOKIE_SAME_SITE=${{ secrets.COOKIE_SAME_SITE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
# Redis
REDIS_PORT=${{ secrets.REDIS_PORT }}
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
EOF
# - name: Check if MySQL container is running
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/be-cd_prod-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ jobs:
COOKIE_DOMAIN=${{ secrets.COOKIE_DOMAIN }}
COOKIE_PATH=${{ secrets.COOKIE_PATH }}
COOKIE_SAME_SITE=${{ secrets.COOKIE_SAME_SITE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
# Redis
REDIS_PORT=${{ secrets.REDIS_PORT }}
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
EOF
- name: Stop and remove existing containers
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/be-cd_test-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ jobs:
COOKIE_DOMAIN=${{ secrets.COOKIE_DOMAIN }}
COOKIE_PATH=${{ secrets.COOKIE_PATH }}
COOKIE_SAME_SITE=${{ secrets.COOKIE_SAME_SITE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
# Redis
REDIS_PORT=${{ secrets.REDIS_PORT }}
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
EOF
- name: Stop and remove existing containers
Expand Down
3 changes: 3 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {
implementation 'org.flywaydb:flyway-core:9.22.3'
implementation 'org.flywaydb:flyway-mysql'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
17 changes: 17 additions & 0 deletions backend/docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'

services:
redis:
image: redis:latest
container_name: redis-local
env_file:
- .env
command: "redis-server --requirepass ${LOCAL_REDIS_PASSWORD}"
ports:
- "${LOCAL_REDIS_PORT}"
networks:
- redis_network

networks:
redis_network:
driver: bridge
43 changes: 43 additions & 0 deletions backend/src/main/java/com/cruru/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.cruru.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.RedisPassword;
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 int port;

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

@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisConfig = new RedisStandaloneConfiguration();
redisConfig.setHostName(host);
redisConfig.setPort(port);
redisConfig.setPassword(RedisPassword.of(password));
return new LettuceConnectionFactory(redisConfig);
}

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
22 changes: 20 additions & 2 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ spring:
file-size-threshold: 2KB
max-file-size: 25MB
max-request-size: 50MB
data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}
password: ${REDIS_PASSWORD}

security:
jwt:
Expand Down Expand Up @@ -116,6 +121,11 @@ spring:
file-size-threshold: 2KB
max-file-size: 25MB
max-request-size: 50MB
data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}
password: ${REDIS_PASSWORD}

security:
jwt:
Expand Down Expand Up @@ -207,7 +217,11 @@ spring:
file-size-threshold: 2KB
max-file-size: 25MB
max-request-size: 50MB

data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}
password: ${REDIS_PASSWORD}
security:
jwt:
token:
Expand Down Expand Up @@ -297,7 +311,11 @@ spring:
file-size-threshold: 2KB
max-file-size: 25MB
max-request-size: 50MB

data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}
password: ${REDIS_PASSWORD}
security:
jwt:
token:
Expand Down
5 changes: 5 additions & 0 deletions backend/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ spring:
open-in-view: false
mail:
host: smtp.gmail.com
data:
redis:
port: 6379
host: localhost
password: password

dataloader:
enable: false
Expand Down

0 comments on commit 10c5073

Please sign in to comment.