Skip to content

Commit

Permalink
add: add the redis config
Browse files Browse the repository at this point in the history
  • Loading branch information
JIUNG9 committed Dec 19, 2023
1 parent 3f95612 commit c151103
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
35 changes: 28 additions & 7 deletions src/main/java/kr/bb/apigateway/common/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
package kr.bb.apigateway.common.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.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.password}")
private String password;



@Bean
public LettuceConnectionFactory connectionFactory() {
return new LettuceConnectionFactory();
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(
host, port);
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(password);
return new JedisConnectionFactory(redisStandaloneConfiguration);
}

@Bean
public RedisTemplate<String, Object> deliveryRedisTemplate(
RedisConnectionFactory connectionFactory) {
public RedisTemplate<String, Object> redisTemplate(
JedisConnectionFactory jedisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setConnectionFactory(jedisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
template.setHashKeySerializer(new GenericToStringSerializer<>(String.class));
template.setHashValueSerializer(new GenericToStringSerializer<>(String.class));
return template;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package kr.bb.apigateway.common.util;

import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


@RequiredArgsConstructor
@NoArgsConstructor
@Component
public class
RedisRefreshTokenUtil {
public class RedisRefreshTokenUtil {

private RedisTemplate<Object, Object> redisTemplate;

public RedisRefreshTokenUtil(
RedisTemplate<Object, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}

private final RedisTemplate<Object, Object> redisTemplate;

public void
saveRefreshToken(String userId, String refreshToken, long expirationTimeInSeconds) {
String key = getRefreshTokenKey(userId);
redisTemplate.opsForValue().set(key, refreshToken, expirationTimeInSeconds, TimeUnit.SECONDS);
redisTemplate.opsForValue()
.set(key, refreshToken, expirationTimeInSeconds, TimeUnit.SECONDS);
}

public String getRefreshToken(String userId) {
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ management:
- "refresh"
- "bus-refresh"

cookie:
refresh:
http:
domain: http://localhost:8000
token:
name: refresh-cookie



5 changes: 4 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
server:
port: 8000
spring:

cloud:
gateway:
httpclient:
Expand All @@ -10,8 +11,10 @@ spring:
main:
web-application-type: reactive
redis:
host: localhost
host: redis
port: 6379
password: 123456

application:
name: apigateway-service
config:
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,3 @@ management:
include:
- "refresh"
- "bus-refresh"

cookie:
refresh:
http:
domain: http://localhost:8000
token:
name: refresh-cookie

0 comments on commit c151103

Please sign in to comment.