+ All Categories
Home > Documents > Redis edu 2

Redis edu 2

Date post: 14-Jul-2015
Category:
Upload: dae-myung-kang
View: 818 times
Download: 3 times
Share this document with a friend
29
REDIS [email protected] collections
Transcript
Page 1: Redis edu 2

REDIS

[email protected]

collections

Page 2: Redis edu 2

Redis collections

Key/Value

List

Set

Sorted Set

Hash

Page 3: Redis edu 2

Key/Value

$> set <KEY> <Value>

$> get <KEY>

Page 4: Redis edu 2

Key/Value

$> mset <KEY> <Value> <KEY> …

$> mget <KEY> <KEY> …

Page 5: Redis edu 2

Ex) Key/Value insert into userinfo(name, email) values (‘charsyam’,’[email protected]’)

Page 6: Redis edu 2

Ex) Key/Value set charsyam:name charsyam set charsyam:email [email protected] mget charsyam:name charsyam:email 1) “charsyam” 2) “[email protected]

Page 7: Redis edu 2

K/V Internal

Hash, O(1)

Separate Chainning With Linked List

Page 8: Redis edu 2

K/V Internal

Page 9: Redis edu 2

Hash Expand #1

Page 10: Redis edu 2
Page 11: Redis edu 2
Page 12: Redis edu 2
Page 13: Redis edu 2

List

$> rpush listname a --- (a) $> rpush listname b --- (a, b) $> lpush listname c --- (c, a, b) $> rpop listname(or lpop listname)

Page 14: Redis edu 2

List

Job Queue가 필요할 때…

Redis 기반의 유명한 Job Queue - SideKiq, Resque - SideKiq 추천

Page 15: Redis edu 2

LPOP, BLPOP

Sidekiq 과 Resque의 큰 차이

LPOP은 polling, BLPOP은 push

LPOP은 list에 데이터가 없으면 바로 리턴 BLPOP은 데이터가 들어올 때 까지 대기함.

Page 16: Redis edu 2

Set

$> sadd setname id1 $> sadd setname id2 $> smember setname 1) “id2” 2) “id1”

Page 17: Redis edu 2

Set

특정 유저를 follow 하는 유저들의 목록등을 저장할 때…

Page 18: Redis edu 2

Sorted Set

$> zadd zsetname 1 “one” $> zadd zsetname 2 “two” $> zadd zsetname 3 “three”

Page 19: Redis edu 2

Sorted Set

$> zrange zsetname 0 -1 1) “one” 2) “two” 3) “three”

Page 20: Redis edu 2

Sorted Set

말 그대로 정렬된 Set User Ranking 등을 구현할 때 유리

Page 21: Redis edu 2

Sorted Set

Set 은 앞의 Hash 형태로 저장되지만 Sorted Set은 SkipList로 구현됨.

Page 22: Redis edu 2

SkipList

지하철 급행이라고 생각하면 쉬움

Page 23: Redis edu 2

Hash insert into userinfo (name, email) values(‘charsyam’, ‘[email protected]’);

Page 24: Redis edu 2

Hash $> hmset charsyam name charsyam email [email protected]

Page 25: Redis edu 2

Hash $> hgetall charsyam 1) “name” 2) “charsyam” 3) “email” 4) “[email protected]

Page 26: Redis edu 2

Hash Hash는 기본 Key/Value 안에 다시 Hash 구조체가 있는 형태

Page 27: Redis edu 2

자주 나오는 질문 K/V로 저장하는게 좋을까요? 아니면 Hash에 저장하는게 좋을까요?

Page 28: Redis edu 2

자주 나오는 질문 그 때, 그 때 다릅니다만… 한 Hash 안에 데이터가 몇 만개 이상이 되는건 좋지 않습니다.

Page 29: Redis edu 2

Thank you.


Recommended