-
스프링 부트 + 레디스 설정/ 테스트Server/Redis 2020. 9. 29. 15:46
@EnableRedisHttpSession @Configuration @PropertySource("classpath:application.properties") public class RedisConfig { @Value("${spring.redis.host}") private String redisHostName; @Value("${spring.redis.port}") private int redisPort; @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } @Bean public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); redisStandaloneConfiguration.setHostName(redisHostName); redisStandaloneConfiguration.setPort(redisPort); LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration); return lettuceConnectionFactory; } @Bean RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); redisTemplate.setConnectionFactory(redisConnectionFactory()); return redisTemplate; } }
예제 서비스
@Service public class RedisTrackingService { @Autowired RedisTemplate<String, Object> template; public void save(Tracking tracking) { template.opsForSet().add("test1",tracking); } }
데이터 확인
'Server > Redis' 카테고리의 다른 글
Spring Boot + Redis 삽질과 디버깅 (0) 2020.10.06 CentOS 8.2 Redis 설치 (0) 2020.09.29