์•ˆ๋…•ํ•˜์„ธ์š”? ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” NoSQL DB ์ค‘ ํ•˜๋‚˜์ธ Redis๋ฅผ Bluemix์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋‚ด์šฉ์„ ๋‹ค๋ฃจ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Redis ๋ž€?

Redis๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค, ์บ์‹œ ๋ฐ ๋ฉ”์‹œ์ง€ ๋ธŒ๋กœ์ปค๋กœ ์‚ฌ์šฉ๋˜๋Š” ์˜คํ”ˆ ์†Œ์Šค (BSD ๋ผ์ด์„ผ์Šค) ์ธ-๋ฉ”๋ชจ๋ฆฌ(In-memory) ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ž์—ด์ด๋‚˜ ํ•ด์‹œ, ๋ฆฌ์ŠคํŠธ, ์ง‘ํ•ฉ, ๋น„ํŠธ๋งต, ์ง€ํ˜•๊ณต๊ฐ„ ์ธ๋ฑ์Šค ๋“ฑ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ž๋ฃŒ ๊ตฌ์กฐ๋ฅผ ์ง€์›ํ•˜๋ฉฐ, ์ž์ฒด์ ์œผ๋กœ ๋ณต์ œ, Lua ์Šคํฌ๋ฆฝํŒ…, LRU ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋”ฐ๋ฅธ key ์ œ๊ฑฐ, ํŠธ๋žœ์žญ์…˜, Pub/Sub ๋ฐ ์˜๊ตฌ ์ €์žฅ ๊ธฐ๋Šฅ์ด ๋‚ด์žฅ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์œ„ํ•œ Reids Sentinel๊ณผ ์ž๋™ ํŒŒํ‹ฐ์…”๋‹์„ ์œ„ํ•œ Redis Cluster ๋„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Redis์˜ ๊ฐ€์žฅ ๋‘๋“œ๋Ÿฌ์ง„ ํŠน์ง•์ด In-memory ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์ด์šฉํ•œ๋‹ค๋Š” ์ ์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ ์ƒ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋ฏ€๋กœ I/O ์†๋„๊ฐ€ ์˜๊ตฌ ์ €์žฅ์†Œ๋ฅผ ์ด์šฉํ•œ ๊ฒฝ์šฐ๋ณด๋‹ค ํ›จ์”ฌ ๋น ๋ฆ…๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ๋น ๋ฅธ ์†๋„์™€ LRU ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ด์šฉํ•œ Key ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ Memory Cache๋กœ ์ด์šฉํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

IBM Bluemix์˜ Redis ์„œ๋น„์Šค

IBM Bluemix์—์„œ๋Š” Redis Composer์™€ Redis Cloud ๋‘๊ฐ€์ง€ ๋ฐฉ์‹์˜ Redis ์„œ๋น„์Šค๋ฅผ ์ œ๊ณต ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

bluemix_redis_services

๋‘ ๊ฐ€์ง€ ์„œ๋น„์Šค ๋ชจ๋‘ Bluemix ์„œ๋น„์Šค์ด๋ฏ€๋กœ Application์ด ํ•ด๋‹น ์„œ๋น„์Šค๋ฅผ Bindํ•ด์„œ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค๋งŒ Plan์— ๋”ฐ๋ฅธ ์ œ๊ณต๋˜๋Š” ์„œ๋น„์Šค ๋‚ด์šฉ, ์ด์šฉ ๊ฐ€๊ฒฉ์ด ๋‹ฌ๋ผ์ง€๋ฏ€๋กœ ์š”๊ฑด์— ๋งž๋Š” ์„œ๋น„์Šค์™€ Plan์„ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

IBM Composer for Redis

IBM Composer for Redis๋Š” Redis Database ์„œ๋ฒ„๋ฅผ Production-ready Database Hosting ํ”Œ๋žซํผ์ธ Compose๋ฅผ ์ด์šฉํ•˜๋Š” ์„œ๋น„์Šค๋กœ, HA ๋ฐ Redundancy๋ฅผ ์ง€์›ํ•˜๋Š” Autoscaling ๋ฐฐํฌ ์‹œ์Šคํ…œ๊ณผ ํ•จ๊ป˜ ์ž๋™ํ™”๋œ ๋ฌด์ค‘๋‹จ ๋ฐฑ์—… ๋ฐ Health ์ฒดํฌ ๊ธฐ๋Šฅ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

compose_for_redis_plan

IBM Composer for Redis ๋ฐ Compose ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋Š” ๋‹ค์Œ ์ •๋ณด๋ฅผ ์ฐธ๊ณ  ํ•˜์„ธ์š”.

Redis Cloud

Bluemix์—์„œ ์ œ๊ณตํ•˜๋Š” ๋˜ ๋‹ค๋ฅธ Redis ์„œ๋น„์Šค๋Š” Redis Cloud์ž…๋‹ˆ๋‹ค. ์ด ์„œ๋น„์Šค๋Š” Composer for Redis์— ๋น„ํ•ด ๋”ฐ๋ผ์„œ ๋‹ค์–‘ํ•œ Plan์„ ์„ ํƒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹จ, 3rd Party์ธ redislabs๋ฅผ ํ†ตํ•ด ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค ์‚ฌ์šฉ์— ๋Œ€ํ•œ ๋ณ„๋„์˜ ๋™์˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด๋ฃŒ Plan์ด ์—†๋Š” IBM Composer for Redis์™€ ๋‹ฌ๋ฆฌ Redis Cloud๋Š” 30MB ์ •๋„ ์šฉ๋Ÿ‰์˜ ์„œ๋น„์Šค ํ•œ ๊ฐœ๋ฅผ ์ƒ์„ฑํ›„ ๋ฌด๋ฃŒ๋กœ ์„ ํƒ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

redis_cloud_free_plan

Redis Cloud์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋Š” ๋‹ค์Œ ์ •๋ณด๋ฅผ ์ฐธ๊ณ  ํ•˜์„ธ์š”.

Redis Cloud๋ฅผ ์ด์šฉํ•œ Redis ์•ฑ ์ƒ์„ฑ

Redis Client๋Š” C, Java์™€ ๊ฐ™์ด ์ „ํ†ต์ ์ธ ๊ฐœ๋ฐœ ์–ธ์–ด ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค์–‘ํ•œ ์–ธ์–ด๋ฅผ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” Redis Client๋ฅผ ์ง€์›ํ•˜๋Š” ์–ธ์–ด ์ •๋ณด ์ž…๋‹ˆ๋‹ค.

redis_clients

๊ทธ ์ค‘์—์„œ Bluemix์—์„œ ์ œ๊ณตํ•˜๋Š” Node.js Runtime์„ ์ด์šฉํ•œ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

Bluemix Cloud Foundry App์˜ ๊ฒฝ์šฐ Command Line Interface (CLI)๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ช…๋ น์ฐฝ์—์„œ manifest.yml์„ ์ด์šฉํ•˜์—ฌ ์•ฑ์„ ์ƒ์„ฑํ•˜๊ณ  Bluemix์— ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค๋งŒ, Bluemix GUI๋ฅผ ์ด์šฉํ•˜๋ฉด Node.js๋ฅผ Runtime์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์ œ๋ฅผ ์†Œ์Šค์ฝ”๋“œ๋กœ ์ƒ์„ฑํ•ด ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ์ด์šฉํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Node.js Runtime App ์ƒ์„ฑ

Bluemix Catalog์˜ Cloud Foundry ์•ฑ ํ•ญ๋ชฉ์„ ์„ ํƒํ•˜๋ฉด Bluemix์—์„œ ์ง€์›ํ•˜๋Š” ๋‹ค์–‘ํ•œ Runtime์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cfapp_nodejs

๊ทธ ์ค‘ SDK for Node.js๋ฅผ ์„ ํƒํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด Node.js Runtime์„ ์ด์šฉํ•˜์—ฌ ์ด๋ฆ„์ด ์ค‘๋ณต๋˜์ง€ ์•Š๊ฒŒ ์ ์ ˆํžˆ ์ž…๋ ฅ ํ›„ ์•ฑ์„ ์ƒ์„ฑ ํ•ฉ๋‹ˆ๋‹ค.

cfapp_nodejs_create

Redis Cloud ์„œ๋น„์Šค ์ƒ์„ฑ ๋ฐ ๋ฐ”์ธ๋“œ

์ •์ƒ์ ์œผ๋กœ ์•ฑ์ด ์ƒ์„ฑํ–ˆ๋‹ค๋ฉด ์ด์ œ๋Š” Redis Cloud ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. Catalog์—์„œ Redis๋กœ ๊ฒ€์ƒ‰์„ ํ•˜๋ฉด ์•ž์„œ ์ด์•ผ๊ธฐํ–ˆ๋“ฏ ๋‘ ๊ฐ€์ง€ ์„œ๋น„์Šค๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ๋Š” ๋ฌด๋ฃŒ Plan์ด ์žˆ๋Š” Redis Cloud๋ฅผ ์„ ํƒํ•˜์—ฌ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

catalog_redis

์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ด์„œ ๋…๋ฆฝ์ ์œผ๋กœ ์‚ฌ์šฉ ํ•  ์ˆ˜๋„ ์žˆ๊ฒ ์ง€๋งŒ Bluemix ์•ฑ์˜ ์žฅ์ ์ธ ์„œ๋น„์Šค ์—ฐ๊ฒฐ์„ ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์„œ๋น„์Šค ์ƒ์„ฑ ์˜ต์…˜ ์ค‘ ์™ผ์ชฝ์— ์—ฐ๊ฒฐํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ•ญ๋ชฉ์„ ์•ž์„œ ์ƒ์„ฑํ–ˆ๋˜ Node.js Runtime ์„ ์„ ํƒํ•˜์—ฌ ์ƒ์„ฑํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

catalog_redis_cloud_create

์„œ๋น„์Šค ์ƒ์„ฑ์ด ์™„๋ฃŒ ๋˜์—ˆ๋‹ค๋ฉด ์„œ๋น„์Šค์™€ ์—ฐ๊ฒฐ๋œ rutime์—์„œ Nodejs ์•ฑ ์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

redis_cloud_bind

Node.js์šฉ ์†Œ์Šค์ฝ”๋“œ ๋‹ค์šด๋กœ๋“œ ๋ฐ Local ์‹คํ–‰ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

์•ž์„œ ์ƒ์„ฑํ•œ Node.js ์•ฑ์˜ ๋Œ€์‹œ๋ณด๋“œ๋กœ ์ง„์ž…ํ•˜๋ฉด ์„ ํƒํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‹คํ–‰ ์ƒํƒœ ๋ฐ ์—ฐ๊ฒฐ๋œ ์„œ๋น„์Šค ์ •๋ณด, ์‚ฌ์šฉ๋Ÿ‰ ๋“ฑ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์˜ˆ์ œ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์ด๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ›„ local ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ Redis๋ฅผ ์œ„ํ•œ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑ ํ›„ ์ด๋ฅผ ๋‹ค์‹œ Bluemix๋กœ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋Œ€์‹œ๋ณด๋“œ์˜ ์™ผํŽธ์—๋Š” ์„ ํƒํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ๋‹ค์–‘ํ•œ ๋ฉ”๋‰ด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ค‘์—์„œ ์‹œ์ž‘ํ•˜๊ธฐ ๋ฉ”๋‰ด๋ฅผ ์„ ํƒํ•˜๋ฉด ํ•ด๋‹น ์•ฑ์— ๋Œ€ํ•œ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๋งํฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

ํ˜น์‹œ ๋‹ค์šด๋กœ๋“œ ๋งํฌ๋ฅผ ์ฐพ์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด CF CLI๋ฅผ ์ด์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ GUID๋ฅผ ํ™•์ธ ํ›„ ์•„๋ž˜ ๋งํฌ๋ฅผ ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ์—ด๋ฉด ์˜ˆ์ œ ์ฝ”๋“œ๊ฐ€ ๋‹ค์šด๋กœ๋“œ ๋ฉ๋‹ˆ๋‹ค.

https://console.ng.bluemix.net/rest/apps/{GUID}/starter-download

์ฐธ๊ณ ๋กœ Region(์ง€์—ญ)์ด ๋ฏธ๊ตญ ๋‚จ๋ถ€๊ฐ€ ์•„๋‹Œ ์˜๊ตญ์ด๋‚˜ ํ˜ธ์ฃผ์ธ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์€ URL์„ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

[์˜๊ตญ] https://console.eu-gb.bluemix.net/rest/apps/{GUID}/starter-download
[ํ˜ธ์ฃผ] https://console.au-syd.bluemix.net/rest/apps/{GUID}/starter-download

์†Œ์Šค์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ–ˆ๋‹ค๋ฉด, ์›๊ฒฉ์ด ์•„๋‹Œ Local ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋˜์–ด์•ผ ํ•  ํ•ญ๋ชฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์œ„์˜ ํ•ญ๋ชฉ์ด ์ž˜ ์„ค์น˜๋˜์—ˆ๋‹ค๋Š” ๊ฐ€์ •์•„๋ž˜ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ์••์ถ•ํ•ด์ œ ํ•ฉ๋‹ˆ๋‹ค.

cfapp_nodejs_src

๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ ์†Œ์Šค ํŒŒ์ผ ์ค‘ manifest.yml ํŒŒ์ผ์ด ์žˆ๋Š”๋ฐ, ์ด ํŒŒ์ผ์—๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ธฐ๋ณธ ์ •๋ณด์™€ ์•ž์„œ ์ƒ์„ฑํ–ˆ๋˜ Redis ์„œ๋น„์Šค๊ฐ€ ์ •์˜ ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cfapp_nodejs_src_manifest

CF CLI๋ฅผ ์ด์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด ํŒŒ์ผ์ด ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ์‹คํ–‰์— ํ•„์š”ํ•œ ๋ชจ๋“ˆ ์„ค์น˜๋ฅผ ์œ„ํ•ด ๋ช…๋ น์ฐฝ์„ ์—ด์–ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ manifest.yml ํŒŒ์ผ์ด ์žˆ๋Š” ๊ณณ์œผ๋กœ ์ด๋™ ํ›„ npm install ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์•ž์„œ ๋งํ–ˆ๋˜ node.js runtime์ด ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด ๋ณ„๋‹ค๋ฅธ ์˜ค๋ฅ˜ ์—†์ด node_modules ํด๋”์— package.json์— ์ •์˜๋œ ๋ชจ๋“ˆ์ด ์„ค์น˜๋ฉ๋‹ˆ๋‹ค.

npm_install2

์ด์ œ ์•ฑ์— ์—ฐ๊ฒฐ๋œ Redis ์„œ๋น„์Šค ์‹ ์ž„ ์ •๋ณด๋ฅผ ํ™•์ธ ํ•˜๊ธฐ ์œ„ํ•ด VCAP_SERVICES ์ •๋ณด๋ฅผ ํ™•์ธ ํ•  ์ฐจ๋ก€์ž…๋‹ˆ๋‹ค. Cloud Foundry ์•ฑ์€ ์•ฑ์— ์—ฐ๊ฒฐ๋œ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ VCAP_SERVICES๋ผ๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •๋ณด๋Š” CF CLI์˜ cf env {appname} ๋ช…๋ น์œผ๋กœ ํ™•์ธ ํ•˜๊ฑฐ๋‚˜ Bluemix ๋Œ€์‹œ๋ณด๋“œ์˜ Runtime ๋ฉ”๋‰ด์˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ํƒญ์„ ํ†ตํ•ด ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

redis_cloud_vcap

์ด์ œ ์ด ๊ฐ’์„ VCAP_SERVICES๋ผ๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์ €์žฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ๊ฐœํ–‰ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜๋ฉด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋ณต์žกํ•ด์ง€๋ฏ€๋กœ ์•ฝ๊ฐ„์˜ ๋ณ€ํ™˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ํฌํ•จ๋œ ๊ฐœํ–‰ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ํ•œ ์ค„๋กœ ๋งŒ๋“ค์–ด ๋†“๋Š” ์ฝ”๋“œ๋ฅผ vcap-local.js ๋ผ๋Š” ํŒŒ์ผ์ด๋ฆ„์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

vcal-local

vcap-local.json์ด๋ผ๋Š” ํŒŒ์ผ์— VCAP_SERVICES์˜ ๋‚ด์šฉ์„ ์ €์žฅํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐœ๋ฐœํ™˜๊ฒฝ์— ๋งž์ถฐ ์„ค์ •ํ•˜๋ฉด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

  • Linux/MacOS

export VCAP_SERVICES=$(node vcap-local.js)

  • Windows

FOR /F "delims=" %i IN ('node vcap-local.js') DO set VCAP_SERVICES=%i

์ด์ œ npm start๋ฅผ ์‹คํ–‰ํ•˜์—ฌ local์—์„œ Cloud Foundry ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธ ํ•ฉ๋‹ˆ๋‹ค.

nodejs_starter_helloworld

Redis Client ๋ชจ๋“ˆ ์„ค์น˜

Node.js๋ฅผ ์œ„ํ•œ Redis Client๋Š” ๋‹ค์–‘ํ•œ client๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค๋งŒ, ์‚ฌ๋žŒ๋“ค์ด ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ์€ redis๋ผ๋Š” ์ด๋ฆ„์˜ ๋ชจ๋“ˆ์ž…๋‹ˆ๋‹ค. ์ด ๋ชจ๋“ˆ์˜ ์„ค์น˜๋ฅผ ์œ„ํ•ด package.json ํŒŒ์ผ์˜ dependency ์ •๋ณด์— redis ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ›„ npm install ๋ช…๋ น์„ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

cfapp_nodejs_src_package_add_redis

์ด๋ฏธ node_module์„ ์„ค์น˜ํ•œ ๊ฒฝ์šฐ๋ผ๋ฉด npm install --save ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ package๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“ˆ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด Local์—์„œ ์‹คํ–‰ ํ•  ์ˆ˜ ์žˆ๋„๋ก Node.js ์•ฑ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์•ฑ์— ์—ฐ๊ฒฐ๋œ ์„œ๋น„์Šค ์‹ ์ž„ ์ •๋ณด๋ฅผ ํ™•์ธ ํ•˜๊ธฐ ์œ„ํ•ด ์•ž์„œ ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ๋“ฑ๋กํ•œ VCAP_SERVICES ์ •๋ณด๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์˜ˆ์ œ ์ฝ”๋“œ์—์„œ๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ์ ‘๊ทผํ•˜๊ธฐ๋ณด๋‹ค๋Š” cfenv๋ผ๋Š” ๋ชจ๋“ˆ์„ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹น ๊ฐ’์„ ์–ป๋„๋กํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” redis์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป์–ด์•ผ ํ•˜๋Š”๋ฐ VCAP_SERVICES์—๋Š” Redis Cloud-lb๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋“ฑ๋ก๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด app.js์—์„œ cfenv์˜ getServiceCreds๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹น ์ •๋ณด๋ฅผ ์–ป๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

vcap_local_rediscloud_getsvc

์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

vcap_local_rediscloud2

Redis Client ํ˜ธ์ถœ ์˜ˆ์ œ ์ž‘์„ฑ

Redis Client๋ฅผ Credential ์ •๋ณด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ดˆ๊ธฐํ™” ํ•˜๊ณ  HTTP PUT/GET ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ์ž…๋ ฅํ•˜๊ณ  ์–ป๋Š” ์˜ˆ์ œ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์ธ ๋‹จ๊ณ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Redis Client ๋ชจ๋“ˆ ๋ฐ ์ดˆ๊ธฐํ™”
  • PUT ๋ฉ”์†Œ๋“œ URL ๋“ฑ๋ก ๋ฐ HSET ๋ช…๋ น์œผ๋กœ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€
  • GET ๋ฉ”์†Œ๋“œ URL ๋“ฑ๋ก ๋ฐ HGET ๋ช…๋ น์œผ๋กœ ์ถ”๊ฐ€๋œ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๊ตฌํ˜„

๋จผ์ € Redis Client ๋ชจ๋“ˆ์„ ๋กœ๋”ฉํ•˜๊ณ  getServiceCreds๋ฅผ ์ด์šฉํ•˜์—ฌ Redis ์‹ ์ž„ ์ •๋ณด๋ฅผ ์–ป์–ด Client๋ฅผ ์ดˆ๊ธฐํ™” ํ•ด์•ผ ํ•˜๋Š”๋ฐ, Credential ์ •๋ณด์— ํ˜ธ์ŠคํŠธ๋ช…, ํฌํŠธ๋ฒˆํ˜ธ ๊ทธ๋ฆฌ๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋‹ด๊ฒจ์žˆ์œผ๋ฏ€๋กœ ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ดˆ๊ธฐํ™” ํ•ฉ๋‹ˆ๋‹ค.

nodejs_redis_createclient

์ด์ œ PUT ๋ฉ”์†Œ๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

nodejs_getput

๊ทธ๋ฆฌ๊ณ  PUT ๋ฉ”์†Œ๋“œ์— HSET ๋ช…๋ น์„ ์œ„ํ•ด ๋‘ ๊ฐœ์˜ parameter๋ฅผ ๋ฐ›๊ณ  HSET ๋ช…๋ น์— ๋Œ€์‘๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

nodejs_getput_redis_impl

๊ทธ๋ฆฌ๊ณ , ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ•ด์•ผ ์ฃผ์–ด์•ผ ๋ชจ๋“ˆ๋กœ ‘body-parser’ ๋ฅผ ์„ค์น˜ํ•ด์•ผ PUT ๋ฉ”์†Œ๋“œ body๋กœ ์ „๋‹ฌ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ JSON Object๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
npm install body-parser --save ๋ช…๋ น์œผ๋กœ ๋ชจ๋“ˆ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋” ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

body-parser

์ด์ œ npm start๋ฅผ ์ด์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹œ์ž‘ ํ•ฉ๋‹ˆ๋‹ค.

vcap_local_rediscloud2

๊ทธ๋ฆฌ๊ณ , ๋‹ค์Œ ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ HGET/HSET์„ ํ…Œ์ŠคํŠธ ํ•ฉ๋‹ˆ๋‹ค.

  • HSET ํ…Œ์ŠคํŠธ

curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"field": "hello", "value": "world"}' http://localhost:6004/hset

์ฒ˜์Œ ์ƒ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ created๋ผ๋Š” ์‘๋‹ต์ด, ๋™์ผํ•œ field๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ updated๋ผ๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

hset_test2

  • HGET ํ…Œ์ŠคํŠธ

curl http://localhost:6004/hget?field=hello

ํ˜ธ์ถœ ์„ฑ๊ณต ์‹œ ๋งˆ์ง€๋ง‰์— ์ž…๋ ฅ๋œ value๊ฐ’์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

hget_test2

์ฐธ๊ณ ๋กœ HSET, HGET ๋ช…๋ น์— ๋Œ€ํ•œ ์ •๋ณด๋Š” ์•„๋ž˜ Redis ํ™ˆํŽ˜์ด์ง€์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์›๊ฒฉ์—์„œ ํ™•์ธ

์ด์ œ Local์—์„œ ํ…Œ์ŠคํŠธ ํ–ˆ๋˜ ์ด ์ •๋ณด๋ฅผ Bluemix์— cf push ๋ช…๋ น์„ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

๋ฐฐํฌ๊ฐ€ ์„ฑ๊ณตํ–ˆ๋‹ค๋ฉด ์ด๋ฒˆ์—” ๋ฐฐํฌ๊ฐ€๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ URL์„ ์ด์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด ๋ด…๋‹ˆ๋‹ค.

  • HSET ํ…Œ์ŠคํŠธ

curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"field": "hello", "value": "world"}' http://hello-redis-nodejs.mybluemix.net/hset

  • HGET ํ…Œ์ŠคํŠธ

curl http://hello-redis-nodejs.mybluemix.net/hget?field=hello

์ด์ œ Nodes.js์—์„œ Redis Client๋ฅผ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•œ Node.js์šฉ Redis ์‚ฌ์šฉ ํ™˜๊ฒฝ ๊ตฌ์„ฑ์— ๋Œ€ํ•œ ์ฝ”๋“œ๋Š” ๋‹ค์Œ GitHub์— ์—…๋ฐ์ดํŠธ ๋˜์–ด ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ  ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ๋Š” Java ๋Ÿฐํƒ€์ž„์ธ Liberty Profile์—์„œ Redis Client๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐ ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ