Redis
- Redis(Remote Dictionary Server)๋ kvp ๊ตฌ์กฐ์ ๋น๊ด๊ณํ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํ ์ธ๋ฉ๋ชจ๋ฆฌ NoSQL ์ ์ฅ์๋ค.
- ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ์บ์, ๋ฉ์์ง ๋ธ๋ก์ปค๋ก ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, ๊ฐ์ข
๋ฐ์ดํฐ ํ์
์ ์ง์ํ๋ค.
Data Types
Strings
- ๋ฌธ์์ด์ ๋ ๋์ค ๊ฐ์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํ์
์ด๋ค.
- INCR, APPEND ๋ฑ ๊ฐ์ข
๋์์ด ๊ฐ๋ฅํ๋ค.
Lists
- ๋ฆฌ์คํธ๋ ๋ฌธ์์ด์ ๋ฆฌ์คํธ๋ค.
- LPUSH, RPUSH ๋ฑ์ ๋์์ด ๊ฐ๋ฅํ๋ค.
Sets
- ์งํฉ์ ๋ฌธ์์ด์ ์์์๋ ์ปฌ๋ ์
์ด๋ค.
- SADD, SPOP, SMEMBERS ๋ฑ์ ๋์์ด ๊ฐ๋ฅํ๋ค.
Hashes
- ํด์๋ ๋ฌธ์์ด ํ๋์ ๋ฌธ์์ด ๊ฐ์ผ๋ก ์ด๋ค์ง ๋งต์ด๋ค.
- ๋ฐ๋ผ์ ์ค๋ธ์ ํธ๋ฅผ ํํํ๊ธฐ์ ๊ฐ์ ์ ํฉํ ํ์
์ด๋ค.
- HSET, HMSET, HGETALL ๋ฑ์ ๋์์ด ๊ฐ๋ฅํ๋ค.
Sorted sets
- ์งํฉ๊ณผ ๋น์ทํ์ง๋ง ์ ์๋ก ์ ๋ ฌ๋๋ ์์์๋ ์ปฌ๋ ์
์ด๋ค.
- ZADD, ZRANK ๋ฑ์ ๋์์ด ๊ฐ๋ฅํ๋ค.
Commands
SET
- ํค์ ๊ฐ์ ์ธ์๋ก ๋ฐ์ kvp ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ค.
redis> SET key โvalueโ
โOKโ
GET
- ํค๋ฅผ ์ธ์๋ก ๋ฐ์ ํด๋น ํค์ ๊ฐ์ ๋ฐํํ๋ค.
redis> SET key โvalueโ
โOKโ
redis> GET key
โvalueโ
DEL
- ํค๋ฅผ ์ธ์๋ก ๋ฐ์ ํด๋น ํค์ ๊ฐ์ ์ญ์ ํ๋ค. ์ญ์ ํ ํค์ ๊ฐ์๋ฅผ ๋ฐํํ๋ฉฐ, ํค๊ฐ ์์ผ๋ฉด ๋ฌด์ํ๋ค.
redis> SET key1 โvalueโ
โOKโ
redis> SET key2 โvalueโ
โOKโ
redis> DEL key1 key2 key3
(integer) 2
INCR
- ํค๋ฅผ ์ธ์๋ก ๋ฐ์ ํด๋น ํค์ ๊ฐ์ 1 ์ฆ๊ฐ์ํค๊ณ ๋ฐํํ๋ค.
redis> SET key โ10โ
โOKโ
redis> INCR key
(integer) 11
redis> GET key
โ11โ
KEYS
- ํจํด์ ์ธ์๋ก ๋ฐ์ ํด๋น ํจํด์ ๋ง๋ ๋ชจ๋ ํค๋ฅผ ๋ฐํํ๋ค.
h?llo
matches hello
, hallo
and hxllo
h*llo
matches hllo
and heeeello
h[ae]llo
matches hello
and hallo
, but not hillo
h[^e]llo
matches hallo
, hbllo
, โฆ but not hello
h[a-b]llo
matches hallo
and hbllo
- ์ค๋ฒํค๋๊ฐ ํฌ๊ธฐ ๋๋ฌธ์ ํ๋ก๋์
ํ๊ฒฝ์์ ์ฌ์ฉํ๋ฉด ์๋๋ค.
redis> SET key1 "value1" key2 "value2"
"OK"
redis> KEYS key1
1) "key1"
redis> KKEYS *
1) "key1"
2) "key2"
SCAN
- ์ปค์ ๊ธฐ๋ฐ ํค ์ดํฐ๋ ์ดํฐ.
- KEYS์ ๋น์ทํ์ง๋ง ์ ํ๋ ๋ฒํท์ ์ํํ๊ธฐ ๋๋ฌธ์ ํ๋ก๋์
์ ์ฌ์ฉํ ์ ์์ ์ ๋๋ก ์ค๋ฒํค๋๊ฐ ์๋ค.
redis> scan 0
1) "17"
2) 1) "key:12"
2) "key:8"
3) "key:4"
4) "key:14"
5) "key:16"
6) "key:17"
7) "key:15"
8) "key:10"
9) "key:3"
10) "key:7"
11) "key:1"
redis> scan 17
1) "0"
2) 1) "key:5"
2) "key:18"
3) "key:0"
4) "key:2"
5) "key:19"
6) "key:13"
7) "key:6"
8) "key:9"
9) "key:11"
ํ์๋ฌธ์
์ฐธ๊ณ ์๋ฃ
์ด ๋ฌธ์๋ฅผ ์ธ์ฉํ ๋ฌธ์