티스토리 뷰
반응형
개발환경 | |
Spring Boot | 2.7.0 |
JDK | 1.8 |
Build | Maven |
https://devhj.tistory.com/24?category=721156
윈도우10 Redis 설치 및 기본 설정
1.Redis란? 레디스(Redis)는 Remote Dictionary Server의 약자로서[4], "키-값" 구조의 비정형 데이터를 저장하고 관리하기 위한 오픈 소스 기반의 비관계형 데이터베이스 관리 시스템(DBMS)이다. 2009년 살
devhj.tistory.com
프로젝트생성 (의존성 : Spring data Redis)
application.yml
spring:
redis:
lettuce:
pool:
max-active: 10
max-idle: 10
min-idle: 2
port: 6379
host: 127.0.0.1
password: 'aaaa'
RedisConfig.java
@Configuration
public class RedisConfig {
@Value("${spring.redis.host}")
private String redisHost;
@Value("${spring.redis.port}")
private String redisPort;
@Value("${spring.redis.password}")
private String redisPassword;
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(redisHost);
redisStandaloneConfiguration.setPort(Integer.parseInt(redisPort));
redisStandaloneConfiguration.setPassword(redisPassword);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
@Bean
public RedisTemplate<String, String> redisTemplate2() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
return redisTemplate;
}
}
RedisController.java
@RestController
public class RedisController {
@Autowired
private RedisTemplate<String, String> redisTemplate2;
@GetMapping("/")
public String test(){
return "test";
}
@GetMapping("/redisTest")
public ResponseEntity<?> addRedisKey() {
ValueOperations<String, String> vop = redisTemplate2.opsForValue();
vop.set("yellow", "banana");
vop.set("red", "apple");
vop.set("green", "watermelon");
return new ResponseEntity<>(HttpStatus.CREATED);
}
@GetMapping("/redisTest/{key}")
public ResponseEntity<?> getRedisKey(@PathVariable String key) {
ValueOperations<String, String> vop = redisTemplate2.opsForValue();
String value = vop.get(key);
return new ResponseEntity<>(value, HttpStatus.OK);
}
}
프로젝트 구조
서버를 구동후 예제처럼 했으면 localhost:8080/redisTest 로 접속하게되면
redis 에 값을 set 하게되고 redis-cli 에서 keys * 명령어를 통해 아래처럼 확인이 가능하다.
반응형
'Spring' 카테고리의 다른 글
Spring Boot Connection Pool 설정 (0) | 2022.11.01 |
---|---|
Spring boot + JPA (1) (0) | 2022.09.26 |
Intellij Spring boot Jmx RMI remote objects have benn exported (0) | 2022.09.13 |
Spring + Mssql + Mybatis 연동 (0) | 2019.12.03 |
Spring Security 구성하기(2) - 패턴구분 및 로그아웃 (0) | 2019.11.26 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- no `meta.properties` found in
- spring boot jpa crud
- 업비트 웹소켓 자바
- kafka redis
- nginx gzip
- actuator prometheus grafana
- SpringBatch 5.1.1
- Enum ==
- AWS 클라우드 환경
- spring boot redis cache
- spring boot jpa
- redis cache
- Enum Equals ==
- kafka srping event
- kafka oubox
- JdbcBatchItem
- spring security
- 업비트 웹소켓
- codecommit repository
- Enum equals
- tomcat gzip
- spring boot gzip
- Spring Actuator
- CompositeItemWriter
- 프라이빗 저장소
- Spring boot Actuator
- oubox pattern
- custom Item writer
- spring redis cache
- sse vs websocket
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함