Skip to content

Commit

Permalink
Merge pull request #65 from Team-PLAT/chore/#64/redisConfig
Browse files Browse the repository at this point in the history
[CHORE] Redis 관련 yml 파일 설정
  • Loading branch information
kyxxgsoo authored Sep 26, 2024
2 parents 37126e4 + 13f1c78 commit 33ffe58
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config
48 changes: 48 additions & 0 deletions src/main/java/com/cabin/plat/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.cabin.plat.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.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@EnableRedisRepositories // redis 활성화
public class RedisConfig {

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

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

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

// @Value("${spring.data.redis.database}")
// private int database;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(redisHost);
redisStandaloneConfiguration.setPort(redisPort);
redisStandaloneConfiguration.setPassword(redisPassword);
// redisStandaloneConfiguration.setDatabase(database);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}

@Bean
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
// Redis key, value 직렬화 설정
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory()); // ConnectionFactory 설정
return redisTemplate;
}
}

0 comments on commit 33ffe58

Please sign in to comment.