SlideShare a Scribd company logo
1 of 27
Download to read offline
Introduction to


Rizky Abdilah, Mindtalk, @rizkyabdilah
Background
●   First release in March 2009
●   Created n maintained by Salvatore Sanfilippo
●   Mostly like Memcache, but with superset
    feature
●   In-memory database, key-value store
●   Open Source, BSD license
●   Sponsored by VMWare
What to Expect
●   Introduction to Redis:
    –   Data Structure Server, Key Feature
    –   Scale it up, Persistence, Who's using Redis
●   Redis and Memcache:
    –   Difference and Similarity
●   Tips with Redis
●   Redis on Mindtalk
Data Structure Server
●   String => “This   is String”
●   List => [“dog”,   “fox”, “dog”, “cat”]
●   Hash Table, Dictionary => {“name”: “Rizky”}
●   Set => set([“dog”,   “fox”, “cat”])
●   Sorted Set:
    –   set([(“dog”, 1), (“fox”, 4), (“cat”, 6)])
Key Features and Cool Stuff
●   All data is in memory (fast)
●   Support for persistence (rdb, aof)
●   Time To Live key (set expired)
●   Atomic Operation (INCR)
●   Lua Scripting (v2.6)
●   Pub/Sub
●   Awesome Community (Friendly)
Persistence
●   RDB, saved periodically or immediately,
    snashotting:
    –   save 900 1 - (15 min, 1 key changed)
    –   LZF compression
●   AOF (Append Only File, work like journal)
    –   appendonly yes
    –   Data safety, sacrificing speed
●   Background and Foreground save
Scale it Up
●   Master-slave, replication for HA
●   Single-threaded, multiple instance in one
    machine
●   Cluster? (to be released)
Who's Using Redis
●   Mindtalk
●   Twitter
●   Instagram
●   Github (Resque)
●   YouPorn
●   Etc (http://redis.io/topics/whos-using-redis)
BO (Basic Operation): “String”
●   SET => SET foo “bar”
●   GET => GET foo
●   INCR => INCR user_id
    –   Increment integer value by 1
●   INCRBY => INCRBY user_id 2
    –   Increment integer value by given amount
●   SETEX => SETEX foo 5 “bar”
    –   Set the value and the expired time
BO List: [“list”]
●   [L|R]PUSH => LPUSH jobs:android “bla”
    –   Prepend or append element in a list
●   [L|R]POP => LPOP jobs:android
    –   Remove and get first element in a list
●   LLEN => LLEN jobs:android
    –   Return length of a list
●   LRANGE => LRANGE jobs:android 0 -1
    –   Return all elements in a list
●   LINDEX => LINDEX jobs:android 0
    –   Get element in a list by its index
BO Hash Table: {“key”: “val”}
●   HSET => HSET user:$id name “Rizky”
    –   Set value in hash table
●   HGET => HGET user:$id name
    –   Return value inside hash table
●   HGETALL => HGETALL user:$id
    –   Return all data in hash table
BO Set: set([“1”])
●   SADD => SADD uniq_ip_visitor “192.168.1.1”
    –   Add element in Set
●   SREM => SREM uniq_ip_visitor “192.168.1.1”
    –   Remove element in Set
●   SMEMBERS => SMEMBERS uniq_ip_visitor
    –   Return all elements in Set
BO Sorted Set: set([(“cat”, 56)])
●   ZADD => ZADD post_view 1 $post_id
    –   Add element in sorted set
●   ZINCRBY => ZINCRBY post_view 1 $post_id
    –   increment
●   ZRANGE => ZRANGE post_view 0 -1
    –   Return all data with ascending sort
●   ZREVRANGE => ZREVRANGE post_view 0 -1
    –   Return all data with descending sort
Advanced Operation
●   Intersect, Diff, Union Set (join?)
●   Intersect, Diff, Union Sorted Set
Advanced Operation [2]
●   Blocking List: B[L|R]POP
●   Multi SET/GET
●   Bit Operation: SETBIT
●   Bitwise Operation: BITOP
●   Append String: APPEND
●   Scription: EVAL
●   Etc (http://redis.io/commands)
Redis and Memcache: Similarity
●   RAM only
●   TTL Support
●   Communicate via TCP
Redis and Memcache: “Difference”
●   Single vs Multithreaded
●   Redis Persistence concern
●   Redis native support for list, hash, set, etc
●   Redis native support for Pub/Sub
●   Memcache support for UDP while Redis
    concern with durability and data safety
    (TCP only)
Tips with Redis
●   Use hash table (HSET) to compress memory
    usage, instead of using plain String (SET) -
    http://mndt.lk/Vr7L - 70MB (SET) vs 16MB
    (HSET)
●   Hash and list ziplist max-size, around 1024
    –   Redis will encode the value inside hash table if the
        biggest entry didn't exceed the threshold (config)
    –   hash-max-ziplist-entries and list-max-
        ziplist-entries
Redis Way
●   “But the Redis Way is that the user must
    understand how things work so that he is able
    to pick the best compromise, and to
    understand how the system will behave
    exactly.” - Salvatore Sanfilippo
●   So, Redis or Memcache?
Redis on Mindtalk
●   Cache
●   REST API Rate Limiting
●   Message Queue (digaku.rpush)
●   Most Viewed Article (last 2 hour)
REST API Rate Limiting
●   Goal: To limit API Call from Client
Message Queue
●   Implemented using BLPOP and RPUSH
    command
Most Viewed Article (last 2 Hour)
Most Viewed Article (last 2 Hour)
●   Batch processing log-file, result saved in
    Redis using Sorted Set
●   ZADD article_view:$hour $count $post_id
●   ZREVRANGE article_view:$hour 0 9
Pub/Sub: digaku.notifier
Pub/Sub: digaku.notifier
●   Long-pooling in client and server
●   Implemented using Redis PUBLISH and
    SUBSCRIBE command
Introduction to Redis

More Related Content

What's hot

Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
Dvir Volk
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
SaltStack – (Not) just another Automation & Remote Execution Tool
SaltStack – (Not) just another Automation & Remote Execution ToolSaltStack – (Not) just another Automation & Remote Execution Tool
SaltStack – (Not) just another Automation & Remote Execution Tool
inovex GmbH
 

What's hot (20)

Linux administration training
Linux administration trainingLinux administration training
Linux administration training
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with Modules
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
 
Hvordan sette opp en OAI-PMH metadata-innhøster
Hvordan sette opp en OAI-PMH metadata-innhøsterHvordan sette opp en OAI-PMH metadata-innhøster
Hvordan sette opp en OAI-PMH metadata-innhøster
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to ask
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layer
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with Gluster
 
Building Awesome CLI apps in Go
Building Awesome CLI apps in GoBuilding Awesome CLI apps in Go
Building Awesome CLI apps in Go
 
MongoDB & PHP
MongoDB & PHPMongoDB & PHP
MongoDB & PHP
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
 
Node.js in production
Node.js in productionNode.js in production
Node.js in production
 
SaltStack – (Not) just another Automation & Remote Execution Tool
SaltStack – (Not) just another Automation & Remote Execution ToolSaltStack – (Not) just another Automation & Remote Execution Tool
SaltStack – (Not) just another Automation & Remote Execution Tool
 
(Practical) linux 101
(Practical) linux 101(Practical) linux 101
(Practical) linux 101
 
Don’t turn your logs into cuneiform
Don’t turn your logs into cuneiformDon’t turn your logs into cuneiform
Don’t turn your logs into cuneiform
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
 

Similar to Introduction to Redis

PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
Andrew Dunstan
 
power point presentation on pig -hadoop framework
power point presentation on pig -hadoop frameworkpower point presentation on pig -hadoop framework
power point presentation on pig -hadoop framework
bhargavi804095
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
Ricard Clau
 
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
Tsukasa Oi
 

Similar to Introduction to Redis (20)

Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Python redis talk
Python redis talkPython redis talk
Python redis talk
 
L3.fa14.ppt
L3.fa14.pptL3.fa14.ppt
L3.fa14.ppt
 
R - the language
R - the languageR - the language
R - the language
 
Redis Modules - Redis India Tour - 2017
Redis Modules - Redis India Tour - 2017Redis Modules - Redis India Tour - 2017
Redis Modules - Redis India Tour - 2017
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdf
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redis
 
Apache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurApache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathur
 
Redis
RedisRedis
Redis
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
Apache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurApache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathur
 
Training
TrainingTraining
Training
 
power point presentation on pig -hadoop framework
power point presentation on pig -hadoop frameworkpower point presentation on pig -hadoop framework
power point presentation on pig -hadoop framework
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributor
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
mapreduce ppt.ppt
mapreduce ppt.pptmapreduce ppt.ppt
mapreduce ppt.ppt
 
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
Creating Secure VM (Comarison between Intel and AMD, and one more thing...) -...
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software Framework
 
Apache Cassandra at Macys
Apache Cassandra at MacysApache Cassandra at Macys
Apache Cassandra at Macys
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Introduction to Redis

  • 1. Introduction to Rizky Abdilah, Mindtalk, @rizkyabdilah
  • 2. Background ● First release in March 2009 ● Created n maintained by Salvatore Sanfilippo ● Mostly like Memcache, but with superset feature ● In-memory database, key-value store ● Open Source, BSD license ● Sponsored by VMWare
  • 3. What to Expect ● Introduction to Redis: – Data Structure Server, Key Feature – Scale it up, Persistence, Who's using Redis ● Redis and Memcache: – Difference and Similarity ● Tips with Redis ● Redis on Mindtalk
  • 4. Data Structure Server ● String => “This is String” ● List => [“dog”, “fox”, “dog”, “cat”] ● Hash Table, Dictionary => {“name”: “Rizky”} ● Set => set([“dog”, “fox”, “cat”]) ● Sorted Set: – set([(“dog”, 1), (“fox”, 4), (“cat”, 6)])
  • 5. Key Features and Cool Stuff ● All data is in memory (fast) ● Support for persistence (rdb, aof) ● Time To Live key (set expired) ● Atomic Operation (INCR) ● Lua Scripting (v2.6) ● Pub/Sub ● Awesome Community (Friendly)
  • 6. Persistence ● RDB, saved periodically or immediately, snashotting: – save 900 1 - (15 min, 1 key changed) – LZF compression ● AOF (Append Only File, work like journal) – appendonly yes – Data safety, sacrificing speed ● Background and Foreground save
  • 7. Scale it Up ● Master-slave, replication for HA ● Single-threaded, multiple instance in one machine ● Cluster? (to be released)
  • 8. Who's Using Redis ● Mindtalk ● Twitter ● Instagram ● Github (Resque) ● YouPorn ● Etc (http://redis.io/topics/whos-using-redis)
  • 9. BO (Basic Operation): “String” ● SET => SET foo “bar” ● GET => GET foo ● INCR => INCR user_id – Increment integer value by 1 ● INCRBY => INCRBY user_id 2 – Increment integer value by given amount ● SETEX => SETEX foo 5 “bar” – Set the value and the expired time
  • 10. BO List: [“list”] ● [L|R]PUSH => LPUSH jobs:android “bla” – Prepend or append element in a list ● [L|R]POP => LPOP jobs:android – Remove and get first element in a list ● LLEN => LLEN jobs:android – Return length of a list ● LRANGE => LRANGE jobs:android 0 -1 – Return all elements in a list ● LINDEX => LINDEX jobs:android 0 – Get element in a list by its index
  • 11. BO Hash Table: {“key”: “val”} ● HSET => HSET user:$id name “Rizky” – Set value in hash table ● HGET => HGET user:$id name – Return value inside hash table ● HGETALL => HGETALL user:$id – Return all data in hash table
  • 12. BO Set: set([“1”]) ● SADD => SADD uniq_ip_visitor “192.168.1.1” – Add element in Set ● SREM => SREM uniq_ip_visitor “192.168.1.1” – Remove element in Set ● SMEMBERS => SMEMBERS uniq_ip_visitor – Return all elements in Set
  • 13. BO Sorted Set: set([(“cat”, 56)]) ● ZADD => ZADD post_view 1 $post_id – Add element in sorted set ● ZINCRBY => ZINCRBY post_view 1 $post_id – increment ● ZRANGE => ZRANGE post_view 0 -1 – Return all data with ascending sort ● ZREVRANGE => ZREVRANGE post_view 0 -1 – Return all data with descending sort
  • 14. Advanced Operation ● Intersect, Diff, Union Set (join?) ● Intersect, Diff, Union Sorted Set
  • 15. Advanced Operation [2] ● Blocking List: B[L|R]POP ● Multi SET/GET ● Bit Operation: SETBIT ● Bitwise Operation: BITOP ● Append String: APPEND ● Scription: EVAL ● Etc (http://redis.io/commands)
  • 16. Redis and Memcache: Similarity ● RAM only ● TTL Support ● Communicate via TCP
  • 17. Redis and Memcache: “Difference” ● Single vs Multithreaded ● Redis Persistence concern ● Redis native support for list, hash, set, etc ● Redis native support for Pub/Sub ● Memcache support for UDP while Redis concern with durability and data safety (TCP only)
  • 18. Tips with Redis ● Use hash table (HSET) to compress memory usage, instead of using plain String (SET) - http://mndt.lk/Vr7L - 70MB (SET) vs 16MB (HSET) ● Hash and list ziplist max-size, around 1024 – Redis will encode the value inside hash table if the biggest entry didn't exceed the threshold (config) – hash-max-ziplist-entries and list-max- ziplist-entries
  • 19. Redis Way ● “But the Redis Way is that the user must understand how things work so that he is able to pick the best compromise, and to understand how the system will behave exactly.” - Salvatore Sanfilippo ● So, Redis or Memcache?
  • 20. Redis on Mindtalk ● Cache ● REST API Rate Limiting ● Message Queue (digaku.rpush) ● Most Viewed Article (last 2 hour)
  • 21. REST API Rate Limiting ● Goal: To limit API Call from Client
  • 22. Message Queue ● Implemented using BLPOP and RPUSH command
  • 23. Most Viewed Article (last 2 Hour)
  • 24. Most Viewed Article (last 2 Hour) ● Batch processing log-file, result saved in Redis using Sorted Set ● ZADD article_view:$hour $count $post_id ● ZREVRANGE article_view:$hour 0 9
  • 26. Pub/Sub: digaku.notifier ● Long-pooling in client and server ● Implemented using Redis PUBLISH and SUBSCRIBE command