SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Linux administration training
Linux administration trainingLinux administration training
Linux administration trainingiman darabi
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redisDvir Volk
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with ModulesItamar Haber
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified LoggingGabor Kozma
 
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østerLibriotech
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014steffenbauer
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
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)PROIDEA
 
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 askCarlos Abalde
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layerKiyoto Tamura
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with GlusterGluster.org
 
Building Awesome CLI apps in Go
Building Awesome CLI apps in GoBuilding Awesome CLI apps in Go
Building Awesome CLI apps in GoSteven Francia
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011sunilar0ra
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use CasesFabrizio Farinacci
 
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 Toolinovex GmbH
 
(Practical) linux 101
(Practical) linux 101(Practical) linux 101
(Practical) linux 101Arie Bregman
 
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 cuneiformAndrey Rebrov
 

La actualidad más candente (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 a Introduction to Redis

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, HerokuRedis Labs
 
Redis Modules - Redis India Tour - 2017
Redis Modules - Redis India Tour - 2017Redis Modules - Redis India Tour - 2017
Redis Modules - Redis India Tour - 2017HashedIn Technologies
 
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 2013Andrew Dunstan
 
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.pdfStephen Lorello
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redisTanu Siwag
 
Apache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurApache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurSiddharth Mathur
 
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 RedisRicard Clau
 
Apache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurApache pig presentation_siddharth_mathur
Apache pig presentation_siddharth_mathurSiddharth Mathur
 
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 frameworkbhargavi804095
 
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 contributorMasahiko Sawada
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard 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
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkThoughtWorks
 

Similar a 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
 

Último

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

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