SlideShare a Scribd company logo
1 of 29
Download to read offline
REDIS
charsyam@naver.com
collections
Redis collections
Key/Value
List
Set
Sorted Set
Hash
Key/Value
$> set <KEY> <Value>
$> get <KEY>
Key/Value
$> mset <KEY> <Value> <KEY> …
$> mget <KEY> <KEY> …
Ex) Key/Value
insert into userinfo(name, email) values
(‘charsyam’,’charsyam@naver.com’)
Ex) Key/Value
set charsyam:name charsyam
set charsyam:email charsyam@naver.com
mget charsyam:name charsyam:email
1) “charsyam”
2) “charsyam@naver.com”
K/V Internal
Hash, O(1)
Separate Chainning With Linked
List
K/V Internal
Hash Expand #1
List
$> rpush listname a --- (a)
$> rpush listname b --- (a, b)
$> lpush listname c --- (c, a, b)
$> rpop listname(or lpop listname)
List
Job Queue가 필요할 때…
Redis 기반의 유명한 Job Queue
- SideKiq, Resque
- SideKiq 추천
LPOP, BLPOP
Sidekiq 과 Resque의 큰 차이
LPOP은 polling, BLPOP은 push
LPOP은 list에 데이터가 없으면 바로
리턴
BLPOP은 데이터가 들어올 때 까지
대기함.
Set
$> sadd setname id1
$> sadd setname id2
$> smember setname
1) “id2”
2) “id1”
Set
특정 유저를 follow 하는 유저들의 목
록등을 저장할 때…
Sorted Set
$> zadd zsetname 1 “one”
$> zadd zsetname 2 “two”
$> zadd zsetname 3 “three”
Sorted Set
$> zrange zsetname 0 -1
1) “one”
2) “two”
3) “three”
Sorted Set
말 그대로 정렬된 Set
User Ranking 등을 구현할 때 유리
Sorted Set
Set 은 앞의 Hash 형태로 저장되지만
Sorted Set은 SkipList로 구현됨.
SkipList
지하철 급행이라고 생각하면 쉬움
Hash
insert into userinfo (name, email)
values(‘charsyam’, ‘charsyam@naver.com’);
Hash
$> hmset charsyam name charsyam email
charsyam@naver.com
Hash
$> hgetall charsyam
1) “name”
2) “charsyam”
3) “email”
4) “charsyam@naver.com”
Hash
Hash는 기본 Key/Value 안에 다시 Hash 구조체
가 있는 형태
자주 나오는 질문
K/V로 저장하는게 좋을까요?
아니면
Hash에 저장하는게 좋을까요?
자주 나오는 질문
그 때, 그 때 다릅니다만…
한 Hash 안에 데이터가 몇 만개 이상이 되는건
좋지 않습니다.
Thank you.

More Related Content

What's hot

파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄SeongHyun Ahn
 
파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄 파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄 SeongHyun Ahn
 
Mongo DB 완벽가이드 - 4장 쿼리하기
Mongo DB 완벽가이드 - 4장 쿼리하기Mongo DB 완벽가이드 - 4장 쿼리하기
Mongo DB 완벽가이드 - 4장 쿼리하기JangHyuk You
 
Redis data design by usecase
Redis data design by usecaseRedis data design by usecase
Redis data design by usecaseKris Jeong
 
MongoDB 하루만에 끝내기
MongoDB 하루만에 끝내기MongoDB 하루만에 끝내기
MongoDB 하루만에 끝내기Seongkuk Park
 
Weird stuff with hashes.key
Weird stuff with hashes.keyWeird stuff with hashes.key
Weird stuff with hashes.keySangyong Sim
 
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈jihoon kim
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제Tae Young Lee
 
파이썬 웹 프로그래밍 2탄
파이썬 웹 프로그래밍 2탄 파이썬 웹 프로그래밍 2탄
파이썬 웹 프로그래밍 2탄 SeongHyun Ahn
 
PHP에서 객체와 데이터 연결 유지
PHP에서 객체와 데이터 연결 유지PHP에서 객체와 데이터 연결 유지
PHP에서 객체와 데이터 연결 유지Yoonwhan Lee
 
Jstl_GETCHA_HANJUNG
Jstl_GETCHA_HANJUNGJstl_GETCHA_HANJUNG
Jstl_GETCHA_HANJUNGJung Han
 

What's hot (12)

파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄
 
파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄 파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄
 
Mongo DB 완벽가이드 - 4장 쿼리하기
Mongo DB 완벽가이드 - 4장 쿼리하기Mongo DB 완벽가이드 - 4장 쿼리하기
Mongo DB 완벽가이드 - 4장 쿼리하기
 
Redis data design by usecase
Redis data design by usecaseRedis data design by usecase
Redis data design by usecase
 
Race condition
Race conditionRace condition
Race condition
 
MongoDB 하루만에 끝내기
MongoDB 하루만에 끝내기MongoDB 하루만에 끝내기
MongoDB 하루만에 끝내기
 
Weird stuff with hashes.key
Weird stuff with hashes.keyWeird stuff with hashes.key
Weird stuff with hashes.key
 
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈
제2회 한글형태소분석기 기술 세니마 발표(solr 활용 입문) by 김지훈
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제
 
파이썬 웹 프로그래밍 2탄
파이썬 웹 프로그래밍 2탄 파이썬 웹 프로그래밍 2탄
파이썬 웹 프로그래밍 2탄
 
PHP에서 객체와 데이터 연결 유지
PHP에서 객체와 데이터 연결 유지PHP에서 객체와 데이터 연결 유지
PHP에서 객체와 데이터 연결 유지
 
Jstl_GETCHA_HANJUNG
Jstl_GETCHA_HANJUNGJstl_GETCHA_HANJUNG
Jstl_GETCHA_HANJUNG
 

More from DaeMyung Kang

How to use redis well
How to use redis wellHow to use redis well
How to use redis wellDaeMyung Kang
 
The easiest consistent hashing
The easiest consistent hashingThe easiest consistent hashing
The easiest consistent hashingDaeMyung Kang
 
How to name a cache key
How to name a cache keyHow to name a cache key
How to name a cache keyDaeMyung Kang
 
Integration between Filebeat and logstash
Integration between Filebeat and logstash Integration between Filebeat and logstash
Integration between Filebeat and logstash DaeMyung Kang
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advanceDaeMyung Kang
 
Massive service basic
Massive service basicMassive service basic
Massive service basicDaeMyung Kang
 
Data Engineering 101
Data Engineering 101Data Engineering 101
Data Engineering 101DaeMyung Kang
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better EngineerDaeMyung Kang
 
Kafka timestamp offset_final
Kafka timestamp offset_finalKafka timestamp offset_final
Kafka timestamp offset_finalDaeMyung Kang
 
Kafka timestamp offset
Kafka timestamp offsetKafka timestamp offset
Kafka timestamp offsetDaeMyung Kang
 
Data pipeline and data lake
Data pipeline and data lakeData pipeline and data lake
Data pipeline and data lakeDaeMyung Kang
 
webservice scaling for newbie
webservice scaling for newbiewebservice scaling for newbie
webservice scaling for newbieDaeMyung Kang
 

More from DaeMyung Kang (20)

Count min sketch
Count min sketchCount min sketch
Count min sketch
 
Redis
RedisRedis
Redis
 
Ansible
AnsibleAnsible
Ansible
 
Why GUID is needed
Why GUID is neededWhy GUID is needed
Why GUID is needed
 
How to use redis well
How to use redis wellHow to use redis well
How to use redis well
 
The easiest consistent hashing
The easiest consistent hashingThe easiest consistent hashing
The easiest consistent hashing
 
How to name a cache key
How to name a cache keyHow to name a cache key
How to name a cache key
 
Integration between Filebeat and logstash
Integration between Filebeat and logstash Integration between Filebeat and logstash
Integration between Filebeat and logstash
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advance
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
Data Engineering 101
Data Engineering 101Data Engineering 101
Data Engineering 101
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better Engineer
 
Kafka timestamp offset_final
Kafka timestamp offset_finalKafka timestamp offset_final
Kafka timestamp offset_final
 
Kafka timestamp offset
Kafka timestamp offsetKafka timestamp offset
Kafka timestamp offset
 
Data pipeline and data lake
Data pipeline and data lakeData pipeline and data lake
Data pipeline and data lake
 
Redis acl
Redis aclRedis acl
Redis acl
 
Coffee store
Coffee storeCoffee store
Coffee store
 
Scalable webservice
Scalable webserviceScalable webservice
Scalable webservice
 
Number system
Number systemNumber system
Number system
 
webservice scaling for newbie
webservice scaling for newbiewebservice scaling for newbie
webservice scaling for newbie
 

Redis edu 2