Spring/DB연동

SpringBoot에서 Redis로 데이터 저장,조회

doriver 2024. 6. 24. 19:24

 

 

1. 의존성 추가

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

 

2. Redis연결 설정 구성

2-1. application.properties에 아래와 같이

spring.redis.host=localhost

spring.redis.port=6379

2-2. @Configuration클래스 구성

 RedisTemplate 스프링빈이 Redis에서 저장,조회를 수행하게됨

 

3. 데이터 저장,조회 구현

redisTemplate.opsForValue().set(key, value);

(String)redisTemplate.opsForValue().get(key);

 

RedisTemplate > ValueOperations > set(), get()

 

4. 테스트

테스트 결과 성공정