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

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:50 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 }}