Info |
---|
https://docs.microsoft.com/ko-kr/azure/azure-cache-for-redis/cache-java-get-started |
Info | |
---|---|
|
00. 사전조건
Info |
---|
|
01. Spring Boot Application 준비
01-01. Spring Boot Application 생성
01-02. Spring Boot Application Workspace 준비
01. 실행환경 청사진
02. 개요
- Azure Cache for Redis
- Azure Cache for Redis는 Redis 소프트웨어를 기반으로 하는 메모리 내 데이터 저장소를 제공합니다. Redis는 백 엔드 데이터 저장소에서 많이 사용하는 애플리케이션의 성능과 확장성을 개선합니다. 자주 액세스하는 데이터를 빠르게 쓰고 읽을 수 있는 서버 메모리에 보관하여 대량의 애플리케이션 요청을 처리할 수 있습니다. Redis는 최신 애플리케이션에 매우 짧은 대기 시간 및 높은 처리량의 데이터 스토리지 솔루션을 제공합니다.
- Azure Cache for Redis 의 가용성 옵션을 참조 하세요.
- Redis Concepts
- 사용예 : 확장 가능한 전자상거래 웹앱
03. 사전조건
Info |
---|
|
04
...
. Create Azure Cache for Redis
...
05.
...
Spring Boot Application
...
준비
Code Blockinfo | |||||
---|---|---|---|---|---|
| |||||
# Specify the DNS URI of your Redis cache.
spring.redis.host=redis20201230.redis.cache.windows.net
# Specify the port for your Redis cache.
spring.redis.port=6380
spring.redis.ssl=true
# Specify the access key for your Redis cache.
spring.redis.password=4pgNlZPhbsla7tgi1s2qONb9YgxttV1zlecnkBJ4uxg= |
Code Block | ||||
---|---|---|---|---|
| ||||
package com.example.redisdemo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
@RestController
public class HelloController {
@Autowired
private StringRedisTemplate template;
@RequestMapping("/")
// Define the Hello World controller.
public String hello() {
ValueOperations<String, String> ops = this.template.opsForValue();
// Add a Hello World string to your cache.
String key = "greeting";
if (!this.template.hasKey(key)) {
ops.set(key, "Hello World!");
}
// Return the string from your cache.
return ops.get(key);
}
} |
04. Execute Spring Boot Application for Azure Redis
https://github.com/Sanses/springboot-reactive-shorturl-webui |
05-01. Git Clone
Code Block |
---|
C:\workspace$ git clone https://github.com/Sanses/springboot-reactive-shorturl-webui.git
Cloning into 'reactive-shorturl-webui'...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 43 (delta 2), reused 39 (delta 1), pack-reused 0
Unpacking objects: 100% (43/43), done.
C:\workspace$ cd springboot-reactive-shorturl-webui |
05-02. reactive-shorturl-webui Application 소개
Code Block |
---|
C:\workspace\springboot-reactive-shorturl-webui$
C:\workspace\springboot-reactive-shorturl-webui>mvnw |
Code Block |
C:\workspace\redisdemo>mvnw clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------< com.examplesansae:redisdemoshorturl >------------------------- [INFO] Building redisdemoshorturl 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 중략 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2123.121120 s [INFO] Finished at: 20202021-1201-30T2202T11:0823:1904+09:00 [INFO] ------------------------------------------------------------------------ C:\workspace\redisdemo>mvnw spring-boot:run [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.example:redisdemo >------------------------ [INFO] Building redisdemo springboot-reactive-shorturl-webui>java -jar target/shorturl-0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ~~~~~~~~~~~~~~~~ 중략 ~~~~~~~~~~~~~~~~~~~ 2020-12-30 22:10:54.930 INFO 7284.jar 2021-01-02 11:24:43.050 INFO 356 --- [ main] o.s.b.wweb.embedded.tomcatnetty.TomcatWebServerNettyWebServer : TomcatNetty initializedstarted withon port(s): 8080 (http) 20202021-1201-3002 2211:1024:5443.941192 INFO 7284356 --- [ main] ocom.apachesansae.catalina.core.StandardService shorturl.ShorturlApplication : StartingStarted service [Tomcat] 2020-12-30 22:10:54.942 INFO 7284 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41] 2020-12-30 22:10:55.045 INFO 7284 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-12-30 22:10:55.046 INFO 7284 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1340 ms 2020-12-30 22:10:55.526 INFO 7284 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-12-30 22:10:55.807 INFO 7284 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-12-30 22:10:55.820 INFO 7284 --- [ main] c.e.redisdemo.RedisdemoApplication : Started RedisdemoApplication in 2.782 seconds (JVM running for 3. 388) C:\workspace\redisdemo>curl localhost:8080 Hello World! C:\workspace\redisdemo> |
...
ShorturlApplication in 10.698 seconds (JVM running for 12.343) |
05-03. Code 검토
Info | ||
---|---|---|
| ||
https://github.com/Sanses/springboot-reactive-shorturl-webui |
06. Deploy Azure WebApp
07. IntelliJ 에서 Azure Redis Caches 확인