SlideShare uma empresa Scribd logo
1 de 56
Baixar para ler offline
Fred Oliveira
@f on twitter and
fred@webreakstuff.com
on that older thing
A trial by fire. Also, probably my
first presentation all set in a
monospaced font.
$ mkdir redis && cd redis
$ wget http://6rq8.sl.pt
$ tar -zxvpf redis-2.0.4.tar.gz
$ cd redis-2.0.4
$ make
# now give it a minute
$ whatis redis
$ whatis redis
redis is an advanced, fast, persistent key-
value database
$ whatis redis
redis is an advanced, fast, persistent key-
value database, developed by Salvatore
Sanfilippo (@antirez)
$ whatis redis
redis is an advanced, fast, persistent key-
value database, developed by Salvatore
Sanfilippo (@antirez), who was recently hired
by VMWare (to keep working on redis).
$ whereis redis
$ whereis redis
places like github, engineyard, forrst,
craigslist
$ whereis redis
places like github, engineyard, forrst,
craigslist, and (I’ll assume) a bunch of
places we won’t hear about.
$ whereis redis
places like github, engineyard, forrst,
craigslist, and (I’ll assume) a bunch of
places we won’t hear about.
(mostly because regardless of how sexy
you think a key-value storage engine
is, not a lot of people talk about
what they actually use.)
$ ./redis-cli
redis> set currentslide “What’s it good for?”
OK
“I see Redis definitely more as a flexible
tool than as a solution specialized to solve a
specific problem: his mixed soul of cache,
store, and messaging server shows this very
well.” - Salvatore Sanfilippo
Possible use cases:
* Caching mechanism (as a substitute for
memcached that doesn’t just store blobs)
* Job management, queueing systems (github’s
resque or Octobot are two good examples)
* IPC (easy to setup up a message passing
system, locally or over a network)
* Locking mechanisms (with commands like setnx
and blpop/brpop)
* Session/Token data store
At WBS, we built a node+redis-based chat
server for a client. Super fast and easily
scalable. Also, of trivial implementation.
Then we built a realtime node/redis/WS based
voting system. Pain points: actually, the only
pain point were browsers that didn’t support
Websockets.
It is very likely that we end up porting many
of our current support processes (queues,
background job management, caching) for our
products to Redis, mostly for its speed and
flexibility.
$ ./redis-cli
redis> set currentslide “Crash course!”
OK
$ ./redis-cli
redis> set currentslide “Redis Data Types”
OK
first, a bit about keys
* binary-safe strings
* stay away from using whitespace
* object:property is a good convention
* SHA hashes are great keys
examples:
* user:name
* lastmessage
* 464A1E96B2D217EBE87449FA8B70E6C7D112560C
redis supports:
* strings
* lists
* sets (+ sorted sets)
* hashes
* strings
set rickroll “never gonna give you up”
OK
get rickroll
“never gonna give you up”
* strings
set count 10 <-- set key
OK
get count <-- get key
“10”
setnx count 9999 <-- set if doesn’t exist
(integer) 0
incr count <-- increment key (returns integer)
(integer) 11
del count <-- deletes the key
(integer) 1
expire count 120 <-- key TTL in secs
(integer) 1
redis supports:
* strings
* lists
* sets (+ sorted sets)
* hashes
redis supports:
* strings
* lists <-- ordered list of binary-safe
strings. implemented on top of the idea for a
linked list (not an array)
* sets (+ sorted sets)
* hashes
redis supports:
* strings
* lists <-- ordered list of binary-safe
strings. implemented on top of the idea for a
linked list (not an array) <-- getting an
element by index is slow, but adding to edges
is super fast (as it should in a db).
* sets (+ sorted sets)
* hashes
* lists
rpush nevergonna “let you down” <-- push right
(integer 1)
rpush nevergonna “run around and desert you”
(integer 2)
rpush nevergonna “make you cry”
(integer 3)
rpush nevergonna “say goodbye”
(integer 4)
rpush nevergonna “tell a lie and hurt you”
(integer 5)
lpush nevergonna “give you up” <-- push left
(integer 6)
* lists (indexes)
[“a”, “b”, “c”, “d”, “e”]
* lists (indexes)
[“a”, “b”, “c”, “d”, “e”]
0 1 2 3 4
* lists (indexes)
[“a”, “b”, “c”, “d”, “e”]
0 1 2 3 4
-5 -4 -3 -2 -1
* lists
rpush nevergonna “let you down” <-- push right
(integer 1)
rpush nevergonna “run around and desert you”
(integer 2)
rpush nevergonna “make you cry”
(integer 3)
rpush nevergonna “say goodbye”
(integer 4)
rpush nevergonna “tell a lie and hurt you”
(integer 5)
lpush nevergonna “give you up” <-- push left
(integer 6)
* lists
lrange 0 2 <-- 3 first elements
1. “give you up”
2. “let you down”
3. “run around and desert you”
lrange 0 -1 <-- first to last
1. “give you up”
2. “let you down”
3. “run around and desert you”
4. “make you cry”
5. “say goodbye”
6. “tell a lie and hurt you”
* lists
llen nevergonna <-- list length
(integer 6)
lpop nevergonna <-- pop from left
“give you up”
lpop nevergonna
“let you down”
rpop nevergonna <-- pop from right
“tell a lie and hurt you”
* lists
lindex nevergonna 0 <-- element at index
“give you up”
ltrim nevergonna 0 2 <-- trims list to [0,1,2]
OK
other commands:
lrem <-- removes x instances of a value
blpop/brpop <-- blocking pop operation. if
list is empty, waits for another client to
lpush or rpush.
sort <-- sorts a list given certain criteria
(sorts numeric lists in ASC by default)
rpoplpush <-- removes from right, adds to left
redis supports:
* strings
* lists
* sets (+ sorted sets)
* hashes
redis supports:
* strings
* lists
* sets (+ sorted sets) <-- unordered
collection of binary-safe strings. no
duplicate elements in sets.
* hashes
redis supports:
* strings
* lists
* sets (+ sorted sets) <-- unordered
collection of binary-safe strings. no
duplicate elements in sets. <-- you can do
interesting things like intersections, unions
and verifying if a key is a member of a set.
* hashes
* sets
sadd beatles “george” <-- add george
sadd beatles “paul” <-- add paul
sadd beatles “john” <-- add john
sadd beatles “ringo” <-- add ringo
smembers beatles <-- list set members
1. “ringo”
2. “john”
3. “george”
4. “paul”
* sets
sismember beatles “john” <-- check presence
(integer) 1
sismember beatles “yoko”
(integer) 0
* sets
implementing things like tags becomes trivial:
sadd taggedwith:design “@jasonsantamaria”
sadd taggedwith:design “@zeldman”
sadd taggedwith:design “@f”
sadd taggedwith:dev “@ezra”
sadd taggedwith:dev “@dhh”
sadd taggedwith:dev “@f”
sinter taggedwith:design taggedwith:dev
^ intersect both sets
1. "@f"
* (sorted) sets
sorted sets are much like regular sets, except
each one member has an associated score. Redis
uses the score to sort between the elements in
the set.
zadd pleague 28 “FC Porto”
zadd pleague 18 “V. Guimarães”
zadd pleague 18 “Benfica”
zadd pleague 16 “Nacional”
zadd pleague 15 “Académica”
* (sorted) sets
zrank pleague “FC Porto” <-- rank, low to high
(integer) 4
zrevrank pleague "FC Porto" <-- high to low
(integer) 0
zrange pleague 0 2 <-- returns 1st to 3rd
1. "Academica"
2. "Nacional"
3. "Benfica"
zrevrange pleague 0 2 <-- high to low
1. "FC Porto"
2. (...)
* (sorted) sets
zcard pleague <-- return cardinality
zscore pleague “Benfica” <-- return the score
zcount pleague 16 18 <-- returns the number of
elements with score between 16 and 18
zremrangebyrank <-- remove by rank range
zremrangebyscore <-- remove by rank score
redis supports:
* strings
* lists
* sets (+ sorted sets)
* hashes
* hashes
useful in the case of web applications, where
storing objects is important. Implementation
is on top of a hash table.
Small hashes, however (with a limited number
of fields and size for values) are implemented
differently in order to be more memory
efficient (to compensate for the overhead of a
traditional hash-table implementation).
* hashes
hset u:fred name “fred”
hset u:fred age “27”
hset u:fred email “fred@webreakstuff.com”
hkeys u:fred <-- return all the keys
hvals u:fred <-- return all the values
hgetall u:fred <-- key(1), value(1)..key(n)..
hincr u:fred age 1 <-- age becomes age++
$ ./redis-cli
redis> set currentslide “Publish/Subscribe”
OK
* pub/sub
Redis natively supports the publish/subscribe
messaging pattern. In the pattern, publishers
don’t know about subscribers. Subscribers
express interest in channels and receive
messages in those channels, with no knowledge
of publishers.
* pub/sub
subscribe messages
Reading messages... (press Ctrl-c to quit)
elsewhere:
publish messages “hello world”
(integer) 1
back in the first client:
1. “message”
2. “messages”
3. “hello world”
* pub/sub
possible use cases:
* alert systems
* chat functionality
* (insert awesomeness)
$ ./redis-cli
redis> set currentslide “A few considerations”
OK
* While the primitives in Redis are pretty
fast, how fast your system actually performs
boils down to how you design the way you store
data.
* Remember there’s no guarantee that data has
been written to disk when a command returns.
* Always design based on how you query.
* Also, you’ll be building your indexes
manually. This means your data will be
replicated in a few places. What they taught
in your DB classes may not apply. De-
normalization is common, natural and necessary
here.
Most previous considerations apply to NoSQL in
general. Relational data makes sense in
relational databases, whereas non-relational
data is perfect for NoSQL. Don’t treat NoSQL
in general or Redis in particular as a silver
bullet.
(although Redis is pretty damn shiny)
$ ./redis-cli
redis> set currentslide “Finally,”
OK
This talk didn’t focus on:
* Scaling redis (trivial with slaveof)
* How fast it is (pretty speedy)
* Comparisons between Redis and key value
stores (because that would be flamebait)
Also, it didn’t talk about
* Clustering Redis (Salvatore himself will
talk about that tomorrow at 3PM on Stage C.
He’s a smart dude, you should go listen to
what he has to say)
...and it didn’t mention,
* Your brain! (I’m going to be speaking about
that sexy beast between your ears tomorrow at
2PM on Stage C. I like to pretend I’m a smart
dude, you should probably go listen to what I
have to say)
redis> exit
>> fred@oreo [~/Projects/redis-2.0.4]
$ _
# thank you!
# email me at fred@webreakstuff.com
# or follow me on twitter - @f

Mais conteúdo relacionado

Último

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 

Último (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 

Destaque

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destaque (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Redis - A Trial by Fire

  • 1. Fred Oliveira @f on twitter and fred@webreakstuff.com on that older thing A trial by fire. Also, probably my first presentation all set in a monospaced font.
  • 2. $ mkdir redis && cd redis $ wget http://6rq8.sl.pt $ tar -zxvpf redis-2.0.4.tar.gz $ cd redis-2.0.4 $ make # now give it a minute
  • 4. $ whatis redis redis is an advanced, fast, persistent key- value database
  • 5. $ whatis redis redis is an advanced, fast, persistent key- value database, developed by Salvatore Sanfilippo (@antirez)
  • 6. $ whatis redis redis is an advanced, fast, persistent key- value database, developed by Salvatore Sanfilippo (@antirez), who was recently hired by VMWare (to keep working on redis).
  • 8. $ whereis redis places like github, engineyard, forrst, craigslist
  • 9. $ whereis redis places like github, engineyard, forrst, craigslist, and (I’ll assume) a bunch of places we won’t hear about.
  • 10. $ whereis redis places like github, engineyard, forrst, craigslist, and (I’ll assume) a bunch of places we won’t hear about. (mostly because regardless of how sexy you think a key-value storage engine is, not a lot of people talk about what they actually use.)
  • 11. $ ./redis-cli redis> set currentslide “What’s it good for?” OK
  • 12. “I see Redis definitely more as a flexible tool than as a solution specialized to solve a specific problem: his mixed soul of cache, store, and messaging server shows this very well.” - Salvatore Sanfilippo
  • 13. Possible use cases: * Caching mechanism (as a substitute for memcached that doesn’t just store blobs) * Job management, queueing systems (github’s resque or Octobot are two good examples) * IPC (easy to setup up a message passing system, locally or over a network) * Locking mechanisms (with commands like setnx and blpop/brpop) * Session/Token data store
  • 14. At WBS, we built a node+redis-based chat server for a client. Super fast and easily scalable. Also, of trivial implementation. Then we built a realtime node/redis/WS based voting system. Pain points: actually, the only pain point were browsers that didn’t support Websockets.
  • 15. It is very likely that we end up porting many of our current support processes (queues, background job management, caching) for our products to Redis, mostly for its speed and flexibility.
  • 16. $ ./redis-cli redis> set currentslide “Crash course!” OK
  • 17. $ ./redis-cli redis> set currentslide “Redis Data Types” OK
  • 18. first, a bit about keys * binary-safe strings * stay away from using whitespace * object:property is a good convention * SHA hashes are great keys examples: * user:name * lastmessage * 464A1E96B2D217EBE87449FA8B70E6C7D112560C
  • 19. redis supports: * strings * lists * sets (+ sorted sets) * hashes
  • 20. * strings set rickroll “never gonna give you up” OK get rickroll “never gonna give you up”
  • 21. * strings set count 10 <-- set key OK get count <-- get key “10” setnx count 9999 <-- set if doesn’t exist (integer) 0 incr count <-- increment key (returns integer) (integer) 11 del count <-- deletes the key (integer) 1 expire count 120 <-- key TTL in secs (integer) 1
  • 22. redis supports: * strings * lists * sets (+ sorted sets) * hashes
  • 23. redis supports: * strings * lists <-- ordered list of binary-safe strings. implemented on top of the idea for a linked list (not an array) * sets (+ sorted sets) * hashes
  • 24. redis supports: * strings * lists <-- ordered list of binary-safe strings. implemented on top of the idea for a linked list (not an array) <-- getting an element by index is slow, but adding to edges is super fast (as it should in a db). * sets (+ sorted sets) * hashes
  • 25. * lists rpush nevergonna “let you down” <-- push right (integer 1) rpush nevergonna “run around and desert you” (integer 2) rpush nevergonna “make you cry” (integer 3) rpush nevergonna “say goodbye” (integer 4) rpush nevergonna “tell a lie and hurt you” (integer 5) lpush nevergonna “give you up” <-- push left (integer 6)
  • 26. * lists (indexes) [“a”, “b”, “c”, “d”, “e”]
  • 27. * lists (indexes) [“a”, “b”, “c”, “d”, “e”] 0 1 2 3 4
  • 28. * lists (indexes) [“a”, “b”, “c”, “d”, “e”] 0 1 2 3 4 -5 -4 -3 -2 -1
  • 29. * lists rpush nevergonna “let you down” <-- push right (integer 1) rpush nevergonna “run around and desert you” (integer 2) rpush nevergonna “make you cry” (integer 3) rpush nevergonna “say goodbye” (integer 4) rpush nevergonna “tell a lie and hurt you” (integer 5) lpush nevergonna “give you up” <-- push left (integer 6)
  • 30. * lists lrange 0 2 <-- 3 first elements 1. “give you up” 2. “let you down” 3. “run around and desert you” lrange 0 -1 <-- first to last 1. “give you up” 2. “let you down” 3. “run around and desert you” 4. “make you cry” 5. “say goodbye” 6. “tell a lie and hurt you”
  • 31. * lists llen nevergonna <-- list length (integer 6) lpop nevergonna <-- pop from left “give you up” lpop nevergonna “let you down” rpop nevergonna <-- pop from right “tell a lie and hurt you”
  • 32. * lists lindex nevergonna 0 <-- element at index “give you up” ltrim nevergonna 0 2 <-- trims list to [0,1,2] OK other commands: lrem <-- removes x instances of a value blpop/brpop <-- blocking pop operation. if list is empty, waits for another client to lpush or rpush. sort <-- sorts a list given certain criteria (sorts numeric lists in ASC by default) rpoplpush <-- removes from right, adds to left
  • 33. redis supports: * strings * lists * sets (+ sorted sets) * hashes
  • 34. redis supports: * strings * lists * sets (+ sorted sets) <-- unordered collection of binary-safe strings. no duplicate elements in sets. * hashes
  • 35. redis supports: * strings * lists * sets (+ sorted sets) <-- unordered collection of binary-safe strings. no duplicate elements in sets. <-- you can do interesting things like intersections, unions and verifying if a key is a member of a set. * hashes
  • 36. * sets sadd beatles “george” <-- add george sadd beatles “paul” <-- add paul sadd beatles “john” <-- add john sadd beatles “ringo” <-- add ringo smembers beatles <-- list set members 1. “ringo” 2. “john” 3. “george” 4. “paul”
  • 37. * sets sismember beatles “john” <-- check presence (integer) 1 sismember beatles “yoko” (integer) 0
  • 38. * sets implementing things like tags becomes trivial: sadd taggedwith:design “@jasonsantamaria” sadd taggedwith:design “@zeldman” sadd taggedwith:design “@f” sadd taggedwith:dev “@ezra” sadd taggedwith:dev “@dhh” sadd taggedwith:dev “@f” sinter taggedwith:design taggedwith:dev ^ intersect both sets 1. "@f"
  • 39. * (sorted) sets sorted sets are much like regular sets, except each one member has an associated score. Redis uses the score to sort between the elements in the set. zadd pleague 28 “FC Porto” zadd pleague 18 “V. Guimarães” zadd pleague 18 “Benfica” zadd pleague 16 “Nacional” zadd pleague 15 “Académica”
  • 40. * (sorted) sets zrank pleague “FC Porto” <-- rank, low to high (integer) 4 zrevrank pleague "FC Porto" <-- high to low (integer) 0 zrange pleague 0 2 <-- returns 1st to 3rd 1. "Academica" 2. "Nacional" 3. "Benfica" zrevrange pleague 0 2 <-- high to low 1. "FC Porto" 2. (...)
  • 41. * (sorted) sets zcard pleague <-- return cardinality zscore pleague “Benfica” <-- return the score zcount pleague 16 18 <-- returns the number of elements with score between 16 and 18 zremrangebyrank <-- remove by rank range zremrangebyscore <-- remove by rank score
  • 42. redis supports: * strings * lists * sets (+ sorted sets) * hashes
  • 43. * hashes useful in the case of web applications, where storing objects is important. Implementation is on top of a hash table. Small hashes, however (with a limited number of fields and size for values) are implemented differently in order to be more memory efficient (to compensate for the overhead of a traditional hash-table implementation).
  • 44. * hashes hset u:fred name “fred” hset u:fred age “27” hset u:fred email “fred@webreakstuff.com” hkeys u:fred <-- return all the keys hvals u:fred <-- return all the values hgetall u:fred <-- key(1), value(1)..key(n).. hincr u:fred age 1 <-- age becomes age++
  • 45. $ ./redis-cli redis> set currentslide “Publish/Subscribe” OK
  • 46. * pub/sub Redis natively supports the publish/subscribe messaging pattern. In the pattern, publishers don’t know about subscribers. Subscribers express interest in channels and receive messages in those channels, with no knowledge of publishers.
  • 47. * pub/sub subscribe messages Reading messages... (press Ctrl-c to quit) elsewhere: publish messages “hello world” (integer) 1 back in the first client: 1. “message” 2. “messages” 3. “hello world”
  • 48. * pub/sub possible use cases: * alert systems * chat functionality * (insert awesomeness)
  • 49. $ ./redis-cli redis> set currentslide “A few considerations” OK
  • 50. * While the primitives in Redis are pretty fast, how fast your system actually performs boils down to how you design the way you store data. * Remember there’s no guarantee that data has been written to disk when a command returns. * Always design based on how you query. * Also, you’ll be building your indexes manually. This means your data will be replicated in a few places. What they taught in your DB classes may not apply. De- normalization is common, natural and necessary here.
  • 51. Most previous considerations apply to NoSQL in general. Relational data makes sense in relational databases, whereas non-relational data is perfect for NoSQL. Don’t treat NoSQL in general or Redis in particular as a silver bullet. (although Redis is pretty damn shiny)
  • 52. $ ./redis-cli redis> set currentslide “Finally,” OK
  • 53. This talk didn’t focus on: * Scaling redis (trivial with slaveof) * How fast it is (pretty speedy) * Comparisons between Redis and key value stores (because that would be flamebait)
  • 54. Also, it didn’t talk about * Clustering Redis (Salvatore himself will talk about that tomorrow at 3PM on Stage C. He’s a smart dude, you should go listen to what he has to say)
  • 55. ...and it didn’t mention, * Your brain! (I’m going to be speaking about that sexy beast between your ears tomorrow at 2PM on Stage C. I like to pretend I’m a smart dude, you should probably go listen to what I have to say)
  • 56. redis> exit >> fred@oreo [~/Projects/redis-2.0.4] $ _ # thank you! # email me at fred@webreakstuff.com # or follow me on twitter - @f