일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Class
- quicksort
- Java
- JPA
- programmers
- Fluent-bit
- redis
- MergeSort
- datatype
- zgc
- lambda
- 연산자
- Kotlin
- Spring Security
- JavaScript
- datastructure
- 자료형
- IAC
- SpringBoot Initializr
- g1gc
- While
- 기초
- If
- C++
- Algorithm
- ansible
- Sprint Security
- For
- UserDetails
- jvm
Archives
- Today
- Total
뭐라도 끄적이는 BLOG
Spring Boot에서 Redis 사용하기 본문
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-web'
사용한 Dependency는 2가지 이다.
spring:
data:
redis:
host: 192.168.0.18
port: 6379
spring boot 2.x버전에서는 spring.redis.host와 spring.redis.port에 설정을 하지만 spring boot 3.x부터는 spring.data.redis에서 설정을 해야 한다.
@RestController
public class HelloController {
@Autowired
StringRedisTemplate stringRedisTemplate;
private final String fruit = "Fruit";
@GetMapping("/hello")
public String hello() {
return "hello";
}
@GetMapping("/setFruit")
public String setFruit(@RequestParam String name) {
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
ops.set(fruit, name);
return "ok";
}
@GetMapping("/getFruit")
public String getFruit() {
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
return ops.get(fruit);
}
}
간단한 RestController를 하나 만들어서 테스트 해볼 수 있다.
참고자료
https://www.baeldung.com/spring-data-redis-properties
반응형
'DataBase > Redis' 카테고리의 다른 글
Redis 소개 및 데이터 타입 (0) | 2023.07.23 |
---|