#20 REDIS
#20.0 Introduction
์๋๊ฐ ๋น ๋ฅธ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ก ๋๋ถ๋ถ์ ๊ฒฝ์ฐ์ ๋ค๋ฅธ SQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๊ฐ์ด ์ฌ์ฉ
ํค-๊ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค, In-Memory ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ก ๊ต์ฅํ ๋น ๋ฅธ ์๋๋ก ์๋ํจ
but ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ์ฉํ๊ธฐ์ ๋น์ฉ์ด ๋ง์ด ๋ฆ โ ๋ค๋ฅธ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ณด์ํ๋ ๋ฐฉ์์ผ๋ก ํ์ฉ
Redis๋ ์บ์ฑ ์ฉ๋๋ก ์ฌ์ฉ#20.2 Strings
-- redis
SET hello world -- key > hello / value > world
GET hello -- world
SET hello bye
GET hello -- bye / ๊ฐ ์์ ๊ฐ๋ฅ
SET users:1 SON
GET users:1 -- SON / ์ ์ผํค
DEL users:1
FLUSHALL -- ์ ๋ถ ์ง์ฐ๊ธฐ
SET users:1 nico NX EX 10 -- ์ข
๋ฃ์ผ์ ์ง์ ๊ฐ๋ฅ
GET users:1 -- 10์ด๋ง ์ ์ฅํจ
SET users:1 nico XX -- ๊ฐ์ด ์กด์ฌํ ๋, users:1์ ๊ฐ์ผ๋ก nico ๋ฃ์ ์ ์๋ค๋ ์๋ฏธ
MSET users:1 SON users:2 CHA users:3 PARK
MGET users:1 users:2 users:3 -- 1) SON 2) CHA 3) PARK
SET visitors 0
INCR visiters // ์ซ์ up
DECR visitors // ์ซ์ down
INCRBY visitors 10 // 10์ฉ up
DECRBY visitors 10 // 10์ฉ down
#20.3 Lists
4,294,967,295 ๊น์ง ์ ์ฅ ๊ฐ๋ฅ
LPUSH l 1 -- LPUSH ๋ฆฌ์คํธ ์ผ์ชฝ์ ๊ฐ์ ์ถ๊ฐ
LRANGE l 0 -1 -- LRANGE ๋ฆฌ์คํธ ์ผ์ชฝ๋ถํฐ
RPUSH l 0
LPOP l -- ๋ฆฌ์คํธ ์ผ์ชฝ ๊ฐ 1๊ฐ ์ ๊ฑฐ
RPOP l
...#20.4 Sets
์ค๋ณต๋ ๊ฐ ํ์ฉ x
SADD votes:song:1 user:1
SADD votes:song:1 user:2
SADD votes:song:1 user:3
SADD votes:song:1 user:2 -- ์คํจ, ๋์ผํ ๊ฐ
SMEMBERS votes:song:1 -- 1) user:1 2) user:2 3) user:3
SISMEMBER votes:song:1 user:1 -- 1
SISMEMBER votes:song:1 user:4 -- 0
SCARD votes:song:1 -- 2
SADD votes:song:2 user:3 user:4 user:5
SMEMBERS votes:song:2 -- 1) user:3 2) user:4 3) user:5
SINTER votes:song:1 votes:song:2 -- user:3 1๊ณผ 2์ ํฌํํ ์ฌ๋
SDIFF votes:song:1 votes:song:2 -- user:1 user:2
SUNION votes:song:1 votes:song:2 -- user:1 user:2... user:5
SREM votes:song:1 user:1 -- delete
...#20.5 Hashes
key์ value์ ์
HSET player:1 name son xp 0 health 100
HGET player:1 name -- son
HGETALL player:1 -- name son xp 0 health 100
HINCRBY player:1 xp 10
HGET player:1 xp -- xp 10
HINCRBY player:1 health -10
HGET player:1 health -- health 90
HMGET player:1 xp health -- 10 90
HSET player:1 name park
HGET player:1 name -- name park
HEXISTS player:1 xp -- 1#20.6 Sorted Sets
ZADD scores 1 user:1 2 user:2 10 user:3 6: user:4
ZRANGE scores 0 -1 -- user:1 user:2 user:4 user:3
ZRANGE scores 0 -1 WITHSCORES -- user:1 1 user:2 2 user:4 6 user:3 10
ZREVRANGE scores 0 -1 -- user:3 user:4 user:2 user:1
ZRANK scores user:1 -- 0
ZRANK scores user:3 -- 3
ZADD scores 20 user:1
ZREVRANGE scores 0 -1 WITHSCORES -- user:1 20 user:3 10 user:4 6 user:2 2
ZINCRBY scores 1 user:2
ZSCORE scores user:1 -- 20
ZRANGEBYSCORE scores 7 50 -- user:2 user:3 user:1
ZCOUNT scores 10 inf -- 2
ZREM scores user:2 -- delLast updated
Was this helpful?