스프링부트 Redis CF서비스 자동연결

Jmnote bot (토론 | 기여)님의 2019년 4월 22일 (월) 12:42 판 (봇: SpringBoot을(를) Spring Boot(으)로 분류 대체함)

1 개요

스프링부트 Redis CF서비스 자동연결
  • CF상에서 bind된 Redis 서비스에 자동연결
  • 프로젝트 생성시 dependencies에서 redis 선택
spring-boot-starter-redis

2 방법

  • MyController.java
@RestController
public class MyController {
	@Autowired
	private StringRedisTemplate template;
	
	@RequestMapping("/")
	public String home() {
		ValueOperations<String, String> ops = this.template.opsForValue();
		String key = "spring.boot.redis.test";
		if (!this.template.hasKey(key)) {
			ops.set(key, "foo");
		}
		return "Found key " + key + ", value=" + ops.get(key);
	}
}

3 같이 보기

4 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}