SlideShare a Scribd company logo
Redis​ ​Cheat​ ​Sheet 
Objects​ ​in​ ​Redis 
● must​ ​have​ ​a​ ​key 
● keys​ ​are​ ​colon​ ​separated 
● value​ ​can​ ​be​ ​hash,​ ​set,​ ​list,​ ​sortedset,​ ​string 
● can​ ​have​ ​an​ ​expiry 
   
Hashes: 
● Use​ ​to​ ​store​ ​"objects"​ ​from​ ​object​ ​oriented​ ​programming 
"blogs:234":​ ​{
​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"id":​ ​234,
​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"title":​ ​"Introduction​ ​to​ ​Redis",
​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"views":​ ​1024
​ ​​ ​​ ​​ ​​ ​​ ​}
● hmset​ ​blogs:234​ ​id​ ​234​ ​title​ ​"Introduction​ ​to​ ​Redis"​ ​views​ ​1024 
● hgetall​ ​blogs:234 
● hincrby​ ​blogs:234​ ​views​ ​1 
 
Sets: 
● Only​ ​unique​ ​items.​ ​No​ ​duplicates 
● Elements​ ​are​ ​not​ ​ordered 
● Can​ ​check​ ​if​ ​element​ ​exists​ ​very​ ​quickly 
● Use​ ​case:​ ​Count​ ​unique​ ​items 
● Use​ ​case:​ ​Check​ ​if​ ​item​ ​exists 
● Use​ ​case:​ ​Perform​ ​logical​ ​UNION​ ​/​ ​INTERSECTION​ ​operations 
● Two​ ​ways​ ​to​ ​represent​ ​same​ ​information,​ ​choose​ ​based​ ​on​ ​use 
case​ ​set​ ​of​ ​integers​ ​consumes​ ​less​ ​memory,​ ​is​ ​very​ ​efficient 
"blogs:234:tags"​ ​==>​ ​set("aws",​ ​"redis",​ ​"cache")
v/s
"tags:aws:blogs"​ ​==>​ ​set(234,​ ​532,​ ​332)
Lists: 
● Duplicates​ ​allowed.  
● Very​ ​well​ ​defined​ ​order​ ​of​ ​elements 
● Expensive​ ​to​ ​check​ ​if​ ​element​ ​already​ ​exists​ ​in​ ​list 
©​ ​2017​ ​HashedIn​ ​Technologies​ ​Pvt.​ ​Ltd. 
● Operations​ ​near​ ​head​ ​/​ ​tail​ ​very​ ​fast. 
● Operations​ ​near​ ​centre​ ​elements​ ​slower 
● Can​ ​use​ ​as​ ​a​ ​queue​ ​or​ ​a​ ​stack 
● Operations​ ​can​ ​block​ ​if​ ​no​ ​elements​ ​are​ ​available,​ ​useful 
● Easy​ ​to​ ​restrict​ ​length​ ​using​ ​ltrim​ ​command 
● Use​ ​case:​ ​Recent​ ​items,​ ​recent​ ​logs 
● Use​ ​case:​ ​Queue​ ​to​ ​maintain​ ​tasks 
 
Sorted​ ​Sets 
● Like​ ​a​ ​set,​ ​only​ ​allows​ ​unique​ ​items 
● Every​ ​element​ ​can​ ​have​ ​a​ ​numeric​ ​score 
● Score​ ​can​ ​represent​ ​anything​ ​-​ ​sales,​ ​count​ ​of​ ​orders,​ ​points​ ​in 
a​ ​game​ ​etc. 
● Elements​ ​are​ ​always​ ​maintained​ ​in​ ​order​ ​of​ ​score  
● If​ ​score​ ​of​ ​two​ ​elements​ ​are​ ​same,​ ​elements​ ​are​ ​sorted​ ​in 
lexicographical​ ​order​ ​-​ ​the​ ​way​ ​you​ ​see​ ​in​ ​oxford's​ ​dictionary 
● Use​ ​case:​ ​Leader​ ​boards​ ​-​ ​Top​ ​10​ ​players,​ ​Products​ ​with​ ​least 
sales,  
● Use​ ​case:​ ​Autocomplete​ ​API  
Strings: 
● Strings​ ​are​ ​binary,​ ​and​ ​can​ ​store​ ​integers,​ ​floats,​ ​text 
● You​ ​can​ ​treat​ ​the​ ​string​ ​as​ ​a​ ​very​ ​large​ ​bitmap 
● You​ ​can​ ​split​ ​the​ ​string​ ​into​ ​smaller​ ​fields,​ ​and​ ​then​ ​set/get 
each​ ​field​ ​using​ ​the​ ​bitfield​ ​command 
 
©​ ​2017​ ​HashedIn​ ​Technologies​ ​Pvt.​ ​Ltd. 

More Related Content

PDF
Redis Workshop on Data Structures, Commands, Administration
PPTX
Azure HDInsight
PDF
Webinar: Managing Real Time Risk Analytics with MongoDB
PDF
Mongo db 3.4 Overview
PDF
Apache Druid®: A Dance of Distributed Processes
PDF
MongoDB on Azure
PDF
Redis basics
PDF
Kicking ass with redis
Redis Workshop on Data Structures, Commands, Administration
Azure HDInsight
Webinar: Managing Real Time Risk Analytics with MongoDB
Mongo db 3.4 Overview
Apache Druid®: A Dance of Distributed Processes
MongoDB on Azure
Redis basics
Kicking ass with redis

Similar to Redis Cheat Sheet (20)

PPTX
Redis Use Patterns (DevconTLV June 2014)
PDF
Use Redis in Odd and Unusual Ways
PDF
Introduction to Redis
PPTX
Redis Indices (#RedisTLV)
PPTX
REDIS327
PPTX
Redis 101 Data Structure
PDF
Redis 맛보기
PDF
Try Redis - interactive Tutorial
PDF
RedisConf18 - Redis Memory Optimization
PDF
Florida Man Uses Cache as Database.pdf
PPTX
Introduction to Redis Data Structures: Hashes
PDF
Paris Redis Meetup Introduction
PDF
Redis everywhere - PHP London
PPTX
Introduction to Redis
PDF
Speed up your Symfony2 application and build awesome features with Redis
PPTX
PPT
Introduction to redis
PPTX
Redis Functions, Data Structures for Web Scale Apps
PPTX
Introducing redis
PDF
Redis memcached pdf
Redis Use Patterns (DevconTLV June 2014)
Use Redis in Odd and Unusual Ways
Introduction to Redis
Redis Indices (#RedisTLV)
REDIS327
Redis 101 Data Structure
Redis 맛보기
Try Redis - interactive Tutorial
RedisConf18 - Redis Memory Optimization
Florida Man Uses Cache as Database.pdf
Introduction to Redis Data Structures: Hashes
Paris Redis Meetup Introduction
Redis everywhere - PHP London
Introduction to Redis
Speed up your Symfony2 application and build awesome features with Redis
Introduction to redis
Redis Functions, Data Structures for Web Scale Apps
Introducing redis
Redis memcached pdf
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Machine Learning_overview_presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Machine Learning_overview_presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A comparative analysis of optical character recognition models for extracting...
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Ad

Redis Cheat Sheet

  • 1. Redis​ ​Cheat​ ​Sheet  Objects​ ​in​ ​Redis  ● must​ ​have​ ​a​ ​key  ● keys​ ​are​ ​colon​ ​separated  ● value​ ​can​ ​be​ ​hash,​ ​set,​ ​list,​ ​sortedset,​ ​string  ● can​ ​have​ ​an​ ​expiry      Hashes:  ● Use​ ​to​ ​store​ ​"objects"​ ​from​ ​object​ ​oriented​ ​programming  "blogs:234":​ ​{ ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"id":​ ​234, ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"title":​ ​"Introduction​ ​to​ ​Redis", ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​"views":​ ​1024 ​ ​​ ​​ ​​ ​​ ​​ ​} ● hmset​ ​blogs:234​ ​id​ ​234​ ​title​ ​"Introduction​ ​to​ ​Redis"​ ​views​ ​1024  ● hgetall​ ​blogs:234  ● hincrby​ ​blogs:234​ ​views​ ​1    Sets:  ● Only​ ​unique​ ​items.​ ​No​ ​duplicates  ● Elements​ ​are​ ​not​ ​ordered  ● Can​ ​check​ ​if​ ​element​ ​exists​ ​very​ ​quickly  ● Use​ ​case:​ ​Count​ ​unique​ ​items  ● Use​ ​case:​ ​Check​ ​if​ ​item​ ​exists  ● Use​ ​case:​ ​Perform​ ​logical​ ​UNION​ ​/​ ​INTERSECTION​ ​operations  ● Two​ ​ways​ ​to​ ​represent​ ​same​ ​information,​ ​choose​ ​based​ ​on​ ​use  case​ ​set​ ​of​ ​integers​ ​consumes​ ​less​ ​memory,​ ​is​ ​very​ ​efficient  "blogs:234:tags"​ ​==>​ ​set("aws",​ ​"redis",​ ​"cache") v/s "tags:aws:blogs"​ ​==>​ ​set(234,​ ​532,​ ​332) Lists:  ● Duplicates​ ​allowed.   ● Very​ ​well​ ​defined​ ​order​ ​of​ ​elements  ● Expensive​ ​to​ ​check​ ​if​ ​element​ ​already​ ​exists​ ​in​ ​list  ©​ ​2017​ ​HashedIn​ ​Technologies​ ​Pvt.​ ​Ltd. 
  • 2. ● Operations​ ​near​ ​head​ ​/​ ​tail​ ​very​ ​fast.  ● Operations​ ​near​ ​centre​ ​elements​ ​slower  ● Can​ ​use​ ​as​ ​a​ ​queue​ ​or​ ​a​ ​stack  ● Operations​ ​can​ ​block​ ​if​ ​no​ ​elements​ ​are​ ​available,​ ​useful  ● Easy​ ​to​ ​restrict​ ​length​ ​using​ ​ltrim​ ​command  ● Use​ ​case:​ ​Recent​ ​items,​ ​recent​ ​logs  ● Use​ ​case:​ ​Queue​ ​to​ ​maintain​ ​tasks    Sorted​ ​Sets  ● Like​ ​a​ ​set,​ ​only​ ​allows​ ​unique​ ​items  ● Every​ ​element​ ​can​ ​have​ ​a​ ​numeric​ ​score  ● Score​ ​can​ ​represent​ ​anything​ ​-​ ​sales,​ ​count​ ​of​ ​orders,​ ​points​ ​in  a​ ​game​ ​etc.  ● Elements​ ​are​ ​always​ ​maintained​ ​in​ ​order​ ​of​ ​score   ● If​ ​score​ ​of​ ​two​ ​elements​ ​are​ ​same,​ ​elements​ ​are​ ​sorted​ ​in  lexicographical​ ​order​ ​-​ ​the​ ​way​ ​you​ ​see​ ​in​ ​oxford's​ ​dictionary  ● Use​ ​case:​ ​Leader​ ​boards​ ​-​ ​Top​ ​10​ ​players,​ ​Products​ ​with​ ​least  sales,   ● Use​ ​case:​ ​Autocomplete​ ​API   Strings:  ● Strings​ ​are​ ​binary,​ ​and​ ​can​ ​store​ ​integers,​ ​floats,​ ​text  ● You​ ​can​ ​treat​ ​the​ ​string​ ​as​ ​a​ ​very​ ​large​ ​bitmap  ● You​ ​can​ ​split​ ​the​ ​string​ ​into​ ​smaller​ ​fields,​ ​and​ ​then​ ​set/get  each​ ​field​ ​using​ ​the​ ​bitfield​ ​command    ©​ ​2017​ ​HashedIn​ ​Technologies​ ​Pvt.​ ​Ltd.