SlideShare a Scribd company logo
How to use redis




                 2012.05.31
www.uajjang.com 미디어 검색팀
                정경석(kris.j)
   What is
   When is the right time to use
   Advantages and disadvantages
   Install
   Run/Test
   Redis Feature
   Performance test
   Cluster Recommendation
   Summary
   REmote DIctionary Server(REDIS)
   One of open source NoSQL(key–value store)
   In memory database
   Supports persistence
   Redis is written in ANSI C(Portabel)
   Sponsored by VMware
   Using github, blizzard, digg, flicker, bump…
   Last stable version 2.4.14(2012.05.31)
   Supports a rich set of data types
    ◦ List, Set, Sorted Set, Hash
   Need a fast response
   Need a Atomic operations
   Need a transaction
   Need a Publish/Subscribe
   Support for persistence
   Use case
    ◦   Job Queue
    ◦   Session store
    ◦   Real time ranking(for all users)
    ◦   Local Address book(Multi client windows, )
   Advantages
    ◦ Speed(80000 TPS depends on System and Net)
    ◦ Command level Atomic Operation(tx operation)
    ◦ Lots of client Lib(Objective-C, C#, Java, node.js,
      Erlang, Ruby…)
    ◦ Supports a serverside locking

   Disadvantages
    ◦ Snapshot IO overhead/Memory overhead
    ◦ Source compile install
    ◦ Whole dataset be loaded into main memory
   Unix/Linux
$   wget http://redis.googlecode.com/files/redis-2.4.14.tar.gz
$   tar xzf redis-2.4.14.tar.gz
$   cd redis-2.4.14
$   make



   Windows 64/32
    ◦ Unofficial support
    ◦ Binary http://github.com/dmajkic/redis/downloads
    ◦ Source export git from
      https://github.com/dmajkic/redis.git and build
// run redis server
$ cd $REDIS_HOME/src
$ ./redis-server
Redis log…


// run redis client
$ $REDIS_HOME/src
$ ./redis-cli
redis 127.0.0.1:6379> set firstkey sample
OK
redis 127.0.0.1:6379> get firstkey
"sample"
redis 127.0.0.1:6379>

    ※ http://try.redis-db.com(ver 2.0.2) test site
   Supports a Expire             Supports a Multi get
redis> set a 1                 redis> set a 1
ok                             OK
redis> expire a 5              redis> set b 12
ok                             OK
redis> get a                   redis> set c 56
"1"                            OK
…                              redis> mget a b c
(5 second later)               1) "1"
redis>                         2) "12"
(nil)                          3) "56"
redis>



※ Supports more then 100 commands.
   Supports a LIST               Supports a SET
redis>del nickname            redis>del nickname
redis> lpush nickname kris    redis> sadd nickname kris
(integer) 1                   (integer) 1
redis> lpush nickname peter   redis> sadd nickname peter
(integer) 2                   (integer) 1
redis> lpush nickname tom     redis> sadd nickname tom
(integer) 3                   (integer) 1
redis> lpush nickname jane    redis> smembers nickname
(integer) 4                   1) "tom"
redis> lrange nickname 0 1    2) "peter"
1) "jane"                     3) "kris"
2) "tom"                      redis> sismember nickname tom
                              (integer) 1

※ Supports Range search           ※ Non-redundant data processing
   Supports a HASH               Supports a Sorted SET
redis>del nickname            redis>del nickname
redis> hset user1 name kris   redis> zadd nickname 10 kris
(integer) 1                   redis> zadd nickname 10 peter
redis> hset user1 lastname    redis> zadd nickname 10 tom
jey                           redis> zadd nickname 10 jane
(integer) 1                   redis> zrevrange nickname 0 2
redis> hset user2 name tom    1) "tom"
(integer) 1                   2) "peter"
redis> hget user1 lastname    3) "kris"
"jey"                         redis> zincrby nickname 1 kris
redis> hgetall user1          "11"
1) "name"                     redis> zrevrange nickname 0 2
2) "kris"                     1) "kris"
3) "lastname"                 2) "tom"
4) "jey"                      3) "peter"
                                  ※ Real time ranking
   Supports a WildCard KeySet
redis> mset node Node.js node06 Node.js ruby18 Ruby1.8
OK
redis> mset ruby19 Ruby1.9 java Java6 mode9 temp
OK
redis> keys node*
1) "node06"
2) "node"
redis> keys ?ode*
1) "mode9"
2) "node06"
3) "node"

    ※ Most command's time complexity is O(1), except ‘keys’ : O(N)
    ※ On desktop environment : 1million keys in 40ms
   Supports a Blocking Queue
※ Client 1                       ※ Client 2
redis> lpush job-list batch01
                                redis> brpop job-list 10
                                1) "job-list"
                                2) "batch01"
                                redis> brpop job-list 10
                                0
                                (nil)
                                (10.28s)
                                redis> brpop job-list 0
redis> lpush job-list batch02
                                1) "job-list"
                                2) "batch02"
                                (5.82s)
   Supports a Publish/Subscribe(PSubscribe)
※ Client 1                      ※ Client 2
redis> publish public-notice   redis> psubscribe public*
'test message'                 Reading messages... (press Ctrl-C
(integer) 1                    to quit)
                               1) "psubscribe"
                               2) "public*"
                               3) (integer) 1

redis> publish public-alert    1)   "pmessage"
'server will shutdon‘          2)   "public*"
(integer) 1                    3)   "public-notice"
                               4)   "test message"
                               1)   "pmessage"
                               2)   "public*"
                               3)   "public-alert"
                               4)   "server will shutdon"
   Test ENV
    ◦ Server : 10.x.x.xx/10.x.x.xx(dual node v2.4.14)
    ◦ Client : Local PC(Thread 100/100M Lan)
    ◦ Command : get/set            Master/Slave Snapshot on




                                                         Redis Server(Master)
                                 set
              Jedis Client                        Real time replication

                                 get
              16,000~                                    Redis Server(Slave)
              20,000 TPS


                 Redis의 TPS는 대부분 Network/CPU 성능에 좌우되며 설정에 따라서 더 빨라질 수 있음.
                 공식 사이트의 측정치는 80000 TPS.
Master
                         Snapshot off
Write




               Slave                    Slave
               Snapshot on              Snapshot on



        Read                  Read
   모든 데이터가 Memory에 적재되므로 적절한 용량산정 필요.(천만
    Key일때 약 500MB메모리 소요)
   Redis서버의 구현이 Single Thread로 구성되어 있으므로 물리
    Core개수 만큼의 Instance 설치.
   현재 release version 2.4.14에서는 Serverside Cluster(Sharding)
    가 구현되어 있지 않음.(Sharding을 사용하기 위해서는 별도의 구현
    필요)
   Persistence지원을 위하여 Snapshot 또는 AOP설정을 사용하여야
    함.(Disk IO overhead 불가피)
    ◦ 실제 Field에서는 Master(Snapshot off) slave(on), slave(on)의 구성을
      사용하고 있으며 Write는 Master, Read는 Slave에서 처리(성능 향상을
      위함.)
   Redis Server 재 시작시 최종 Snapshot/AOF의 데이터가 로드됨.
   A common convention is to use “obj-type:id:field”
   Amazon EC2 Server에서 서비스중인 사례.
    ◦ 40000~100000 TPS처리중임.
    ◦ 20GB의 데이터 셋
    ◦ Amazon EC2 Server의 Virtualize 특성 때문에 Snapshot 사용 문제
      원인 fork() 시간이 너무 길게 걸림.)
    ◦ 위의 문제로 인하여 Snapshot을 off하고 AOF(Append Only File)기능을
      사용함.
    ◦ 위와 같은 설정에서 서비스 이상없이 운영중임.
   사용사례 Posting(1억2천만 사용자 대상 실시간 로그인 통계)
    ◦ http://blog.getspool.com/2011/11/29/fast-easy-realtime-
      metrics-using-redis-bitmaps/
    ◦ Unique방문자수 집계
      일간 : 50ms, 주간 : 392ms, 월간 : 1624ms

More Related Content

PDF
MySQL 5.7の罠があなたを狙っている
PDF
PPTX
NuxtでAPIサーバー立ててみた
PDF
Project Loom - 限定継続と軽量スレッド -
PPTX
SSRF For Bug Bounties
PDF
単なるキャッシュじゃないよ!?infinispanの紹介
PDF
内製ツールを使ったチート診断・脆弱性診断
PDF
BHyVeってなんや
MySQL 5.7の罠があなたを狙っている
NuxtでAPIサーバー立ててみた
Project Loom - 限定継続と軽量スレッド -
SSRF For Bug Bounties
単なるキャッシュじゃないよ!?infinispanの紹介
内製ツールを使ったチート診断・脆弱性診断
BHyVeってなんや

What's hot (20)

PDF
コンテナ未経験新人が学ぶコンテナ技術入門
PDF
ElastiCacheを利用する上でキャッシュをどのように有効に使うべきか
PDF
XSS再入門
PPTX
PenTesterが知っている危ないAWS環境の共通点
PDF
AWS + Windows(C#)で構築する.NET最先端技術によるハイパフォーマンスウェブアプリケーション開発実践
PDF
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
PPTX
Docker Tokyo
PDF
SpotBugs(FindBugs)による 大規模ERPのコード品質改善
PPTX
PHPとシグナル、その裏側
PPTX
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
PDF
Jenkins를 활용한 Openshift CI/CD 구성
PDF
Linux女子部 systemd徹底入門
PDF
Linux KVMではじめるカンタン仮想化入門
PDF
怖くないSpring Bootのオートコンフィグレーション
PDF
詳説データベース輪読会: 分散合意その2
KEY
クックパッドでのemr利用事例
PDF
SSH力をつけよう
PDF
Concurrency in action - chapter 7
PDF
The BlackBox Project: Safely store secrets in Git/Mercurial (originally for P...
PDF
君はyarn.lockをコミットしているか?
コンテナ未経験新人が学ぶコンテナ技術入門
ElastiCacheを利用する上でキャッシュをどのように有効に使うべきか
XSS再入門
PenTesterが知っている危ないAWS環境の共通点
AWS + Windows(C#)で構築する.NET最先端技術によるハイパフォーマンスウェブアプリケーション開発実践
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
Docker Tokyo
SpotBugs(FindBugs)による 大規模ERPのコード品質改善
PHPとシグナル、その裏側
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
Jenkins를 활용한 Openshift CI/CD 구성
Linux女子部 systemd徹底入門
Linux KVMではじめるカンタン仮想化入門
怖くないSpring Bootのオートコンフィグレーション
詳説データベース輪読会: 分散合意その2
クックパッドでのemr利用事例
SSH力をつけよう
Concurrency in action - chapter 7
The BlackBox Project: Safely store secrets in Git/Mercurial (originally for P...
君はyarn.lockをコミットしているか?
Ad

Viewers also liked (12)

PPTX
이것이 레디스다.
PPTX
This is redis - feature and usecase
PDF
Redis edu 1
PPTX
Redis Introduction
KEY
Farma Presentatie
PDF
Redis dict and_rehash
PDF
Redis ndc2013
PDF
C* Summit 2013: Cassandra at Instagram by Rick Branson
PPTX
Node Js와 Redis를 사용한 구조화된 데이터
PDF
[2B3]ARCUS차별기능,사용이슈,그리고카카오적용사례
PDF
AWS 시작하기 및 Amazon S3 살펴보기 (윤석찬) - AWS 웨비나 시리즈
PDF
Lightning Talk: jsPDF
이것이 레디스다.
This is redis - feature and usecase
Redis edu 1
Redis Introduction
Farma Presentatie
Redis dict and_rehash
Redis ndc2013
C* Summit 2013: Cassandra at Instagram by Rick Branson
Node Js와 Redis를 사용한 구조화된 데이터
[2B3]ARCUS차별기능,사용이슈,그리고카카오적용사례
AWS 시작하기 및 Amazon S3 살펴보기 (윤석찬) - AWS 웨비나 시리즈
Lightning Talk: jsPDF
Ad

Similar to REDIS intro and how to use redis (20)

PDF
Redis SoCraTes 2014
PPT
Introduction to redis
KEY
Building Scalable, Distributed Job Queues with Redis and Redis::Client
KEY
Redis - N✮SQL Berlin
PPT
Python redis talk
PDF
Redispresentation apac2012
PPT
Redis And python at pycon_2011
KEY
Redis in Practice
PDF
Redis - Usability and Use Cases
PDF
Redis begins
PDF
Paris Redis Meetup Introduction
PDF
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
PDF
Speed up your Symfony2 application and build awesome features with Redis
PDF
Introduction to Redis
PPTX
PDF
Introduction to Redis
PDF
Introduction to Redis
PPTX
Redis in 20 minutes
PDF
Redis for the Everyday Developer
PDF
Introduction to Redis - LA Hacker News
Redis SoCraTes 2014
Introduction to redis
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Redis - N✮SQL Berlin
Python redis talk
Redispresentation apac2012
Redis And python at pycon_2011
Redis in Practice
Redis - Usability and Use Cases
Redis begins
Paris Redis Meetup Introduction
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
Speed up your Symfony2 application and build awesome features with Redis
Introduction to Redis
Introduction to Redis
Introduction to Redis
Redis in 20 minutes
Redis for the Everyday Developer
Introduction to Redis - LA Hacker News

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I

REDIS intro and how to use redis

  • 1. How to use redis 2012.05.31 www.uajjang.com 미디어 검색팀 정경석(kris.j)
  • 2. What is  When is the right time to use  Advantages and disadvantages  Install  Run/Test  Redis Feature  Performance test  Cluster Recommendation  Summary
  • 3. REmote DIctionary Server(REDIS)  One of open source NoSQL(key–value store)  In memory database  Supports persistence  Redis is written in ANSI C(Portabel)  Sponsored by VMware  Using github, blizzard, digg, flicker, bump…  Last stable version 2.4.14(2012.05.31)  Supports a rich set of data types ◦ List, Set, Sorted Set, Hash
  • 4. Need a fast response  Need a Atomic operations  Need a transaction  Need a Publish/Subscribe  Support for persistence  Use case ◦ Job Queue ◦ Session store ◦ Real time ranking(for all users) ◦ Local Address book(Multi client windows, )
  • 5. Advantages ◦ Speed(80000 TPS depends on System and Net) ◦ Command level Atomic Operation(tx operation) ◦ Lots of client Lib(Objective-C, C#, Java, node.js, Erlang, Ruby…) ◦ Supports a serverside locking  Disadvantages ◦ Snapshot IO overhead/Memory overhead ◦ Source compile install ◦ Whole dataset be loaded into main memory
  • 6. Unix/Linux $ wget http://redis.googlecode.com/files/redis-2.4.14.tar.gz $ tar xzf redis-2.4.14.tar.gz $ cd redis-2.4.14 $ make  Windows 64/32 ◦ Unofficial support ◦ Binary http://github.com/dmajkic/redis/downloads ◦ Source export git from https://github.com/dmajkic/redis.git and build
  • 7. // run redis server $ cd $REDIS_HOME/src $ ./redis-server Redis log… // run redis client $ $REDIS_HOME/src $ ./redis-cli redis 127.0.0.1:6379> set firstkey sample OK redis 127.0.0.1:6379> get firstkey "sample" redis 127.0.0.1:6379> ※ http://try.redis-db.com(ver 2.0.2) test site
  • 8. Supports a Expire  Supports a Multi get redis> set a 1 redis> set a 1 ok OK redis> expire a 5 redis> set b 12 ok OK redis> get a redis> set c 56 "1" OK … redis> mget a b c (5 second later) 1) "1" redis> 2) "12" (nil) 3) "56" redis> ※ Supports more then 100 commands.
  • 9. Supports a LIST  Supports a SET redis>del nickname redis>del nickname redis> lpush nickname kris redis> sadd nickname kris (integer) 1 (integer) 1 redis> lpush nickname peter redis> sadd nickname peter (integer) 2 (integer) 1 redis> lpush nickname tom redis> sadd nickname tom (integer) 3 (integer) 1 redis> lpush nickname jane redis> smembers nickname (integer) 4 1) "tom" redis> lrange nickname 0 1 2) "peter" 1) "jane" 3) "kris" 2) "tom" redis> sismember nickname tom (integer) 1 ※ Supports Range search ※ Non-redundant data processing
  • 10. Supports a HASH  Supports a Sorted SET redis>del nickname redis>del nickname redis> hset user1 name kris redis> zadd nickname 10 kris (integer) 1 redis> zadd nickname 10 peter redis> hset user1 lastname redis> zadd nickname 10 tom jey redis> zadd nickname 10 jane (integer) 1 redis> zrevrange nickname 0 2 redis> hset user2 name tom 1) "tom" (integer) 1 2) "peter" redis> hget user1 lastname 3) "kris" "jey" redis> zincrby nickname 1 kris redis> hgetall user1 "11" 1) "name" redis> zrevrange nickname 0 2 2) "kris" 1) "kris" 3) "lastname" 2) "tom" 4) "jey" 3) "peter" ※ Real time ranking
  • 11. Supports a WildCard KeySet redis> mset node Node.js node06 Node.js ruby18 Ruby1.8 OK redis> mset ruby19 Ruby1.9 java Java6 mode9 temp OK redis> keys node* 1) "node06" 2) "node" redis> keys ?ode* 1) "mode9" 2) "node06" 3) "node" ※ Most command's time complexity is O(1), except ‘keys’ : O(N) ※ On desktop environment : 1million keys in 40ms
  • 12. Supports a Blocking Queue ※ Client 1 ※ Client 2 redis> lpush job-list batch01 redis> brpop job-list 10 1) "job-list" 2) "batch01" redis> brpop job-list 10 0 (nil) (10.28s) redis> brpop job-list 0 redis> lpush job-list batch02 1) "job-list" 2) "batch02" (5.82s)
  • 13. Supports a Publish/Subscribe(PSubscribe) ※ Client 1 ※ Client 2 redis> publish public-notice redis> psubscribe public* 'test message' Reading messages... (press Ctrl-C (integer) 1 to quit) 1) "psubscribe" 2) "public*" 3) (integer) 1 redis> publish public-alert 1) "pmessage" 'server will shutdon‘ 2) "public*" (integer) 1 3) "public-notice" 4) "test message" 1) "pmessage" 2) "public*" 3) "public-alert" 4) "server will shutdon"
  • 14. Test ENV ◦ Server : 10.x.x.xx/10.x.x.xx(dual node v2.4.14) ◦ Client : Local PC(Thread 100/100M Lan) ◦ Command : get/set Master/Slave Snapshot on Redis Server(Master) set Jedis Client Real time replication get 16,000~ Redis Server(Slave) 20,000 TPS Redis의 TPS는 대부분 Network/CPU 성능에 좌우되며 설정에 따라서 더 빨라질 수 있음. 공식 사이트의 측정치는 80000 TPS.
  • 15. Master Snapshot off Write Slave Slave Snapshot on Snapshot on Read Read
  • 16. 모든 데이터가 Memory에 적재되므로 적절한 용량산정 필요.(천만 Key일때 약 500MB메모리 소요)  Redis서버의 구현이 Single Thread로 구성되어 있으므로 물리 Core개수 만큼의 Instance 설치.  현재 release version 2.4.14에서는 Serverside Cluster(Sharding) 가 구현되어 있지 않음.(Sharding을 사용하기 위해서는 별도의 구현 필요)  Persistence지원을 위하여 Snapshot 또는 AOP설정을 사용하여야 함.(Disk IO overhead 불가피) ◦ 실제 Field에서는 Master(Snapshot off) slave(on), slave(on)의 구성을 사용하고 있으며 Write는 Master, Read는 Slave에서 처리(성능 향상을 위함.)  Redis Server 재 시작시 최종 Snapshot/AOF의 데이터가 로드됨.  A common convention is to use “obj-type:id:field”
  • 17. Amazon EC2 Server에서 서비스중인 사례. ◦ 40000~100000 TPS처리중임. ◦ 20GB의 데이터 셋 ◦ Amazon EC2 Server의 Virtualize 특성 때문에 Snapshot 사용 문제  원인 fork() 시간이 너무 길게 걸림.) ◦ 위의 문제로 인하여 Snapshot을 off하고 AOF(Append Only File)기능을 사용함. ◦ 위와 같은 설정에서 서비스 이상없이 운영중임.  사용사례 Posting(1억2천만 사용자 대상 실시간 로그인 통계) ◦ http://blog.getspool.com/2011/11/29/fast-easy-realtime- metrics-using-redis-bitmaps/ ◦ Unique방문자수 집계  일간 : 50ms, 주간 : 392ms, 월간 : 1624ms