SlideShare una empresa de Scribd logo
1 de 55
Redis




                               Thorsten Böttger
                                 Sharesight.co.nz
                           WellRailed 23/05/2012
        http://www.flickr.com/photos/linecon0/1085617988
https://github.com/plataformatec/devise/issues/1856
What is
Redis?


http://www.flickr.com/photos/spisharam/2742433355/
key-value store
    http://www.flickr.com/photos/jamesclay/2312912612/
memcached on steroids
no document database




         http://www.flickr.com/photos/linneberg/4481309196/
no relational database




          http://www.flickr.com/photos/lencioni/203030529/
Salvatore Sanfilippo




             Pieter Noordhuis
Open Source
design principle


“I see Redis definitely more as a flexible tool than
as a solution specialized to solve a specific
problem.” — Salvatore Sanfilippo
Characteristics   http://www.flickr.com/photos/gjw/487364375/
It’s incredibly fast!
Craftmanship




               http://www.flickr.com/photos/gte491n/4335439637/
Love
Not like this guy...




                          http://www.flickr.com/photos/brettmorrison/4718717523/
Alive and kicking


       +
Well documented
Easy to install
Easy to configure
     http://www.flickr.com/photos/mag3737/3176598270/
XML
plain text
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
pidfile /var/run/redis.pid

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for incoming connections.
#
# bind 127.0.0.1

#   Specify the path for the unix socket that will be used to listen for
#   incoming connections. There is no default, so Redis will not listen
#   on a unix socket when not specified.
#
#   unixsocket /tmp/redis.sock
#   unixsocketperm 755

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
or on-the-fly




$ redis-cli

CONFIG SET loglevel debug
Easy to use
http://www.flickr.com/photos/derekgavey/4243329714/
Administration
Replication

                   Master



        Slave         Slave   Slave




Slave      Slave
Persistence
        Redis Data Backup




              Redis



Redis      Redis      Redis   Redis


               time
Persistence
    Append-Only File




        Redis



∂      ∂          ∂    ∂


           time
Security
http://www.flickr.com/photos/takkaria/2520731995/




Use Cases
Cache Store
  https://github.com/jodosha/redis-store


Session Store
  https://github.com/mattmatt/redis-session-store


Counters
  stats, API requests per hour, DoS, Spam
Url Shortener
        Redis    string

    a6hz89z:
    https://mysite/
    a/very/deep/
    link?
    with=params
Wizards
                                   Redis
Form Step 1                                hash
                             a: ‘name’
                             b: ‘email’
Form Step 2
                                                  after 3rd step
              intermediate
                 results
                             ...                                   DB
                             k: ...
Form Step 3
Map-Reduce
                     Redis
                             hash
          Worker
                   sums[a]
Map

      {   Worker   sums[b]
                   sums[c]
                             }      Reduce




          Worker
Job Queue
                            Redis
                                      list
Rails App       Push

                       now
                       1.hour.ago
                       ...
                       2.hours.ago
                                             Pop
                                                     Worker


      Resque           https://github.com/defunkt/resque
      Sidekiq          https://github.com/mperham/sidekiq
Unique Visitors
      Redis
              set

    user A
    user K
    user Y
List of online users
         Redis    set


       ⌚ user A
       ⌚ user K
       ⌚ user Y
Todo lists
     Redis
            sorted set

  1. this
  2. that
  3. ...
Leaderboard
     Redis
         sorted set

   7. top
   3. middle
   1. loser
Push Notifications
                    Redis
Event                       pubsub

                  channel A
Event
        Publish   channel B
                                                 Pusher
                                     Subscribe


                  ...

Event
Chat system
                       Redis
                               pubsub

         Publish
                     channel A          Subscribe


         Subscribe                      Publish



user A               channel B                      user B
Communication
         between Apps
                       Redis
                               pubsub


Rails
         Publish
                     channel A          Subscribe
                                                     Any
         Subscribe                      Publish
                                                    other
                     channel B
Activity Feed

             Redis
action                 list




                              }
         A wrote
         B is following           display


         A added
                     LTRIM
         A wrote
Activity Feed 2
where every user shows up only once

                                Redis
       action     sorted set                         hash

                t3: A          A: ‘A wrote’
                t2: B          B: ‘B is following’
                t1: C          C: ‘C added’
Tagging
                       Redis
              hash                 hash                 hash

book_1               book_2               book_2
name: ...            name: ...            name: ...
author: ...          author: ...          author: ...
                        set                   set

         tag:redis             tag:rails
         1                     2
                               3
Queue-activated
 shell scripts
Limits & drawbacks




              http://www.flickr.com/photos/36117591@N04/3558894634/
Big Data
Scalability
To the rescue: Clustering
                Master

      Master                Master

               consistent
   Master                      Master
               hashing

     Master                 Master
                Master
It’s not a Database
Not Exchangeable
Further readings
http://redis.io
RailsConf 2012




http://www.youtube.com/watch?v=VOFTop3AMZ8
Thank you!




                                                        Thorsten Böttger
                                                                  @enebo
                                                             http://mt7.de
http://www.flickr.com/photos/analogian/5913840143/   http://Sharesight.co.nz

Más contenido relacionado

Último

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Destacado

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
Kurio // The Social Media Age(ncy)
 
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
Saba Software
 

Destacado (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 - An Introduction

Notas del editor

  1. Kiwi accent, still lose me on the phone\n#bedrooms instead of square meters\nThanks, Driver!\n
  2. Salvatore Sanfilippo, Pieter Noordhuis, Paul Maritz, Jose Valim, DHH\nthey have something in common\n
  3. \n
  4. \n
  5. NoSQL, REmote DIctionary Server, written in C, single-threaded, all data in memory\n\n...like memcached\n
  6. advanced data structures\npersistence\n
  7. supports advanced data structures\nbut not THAT advanced \n
  8. set-based queries, but not with that highly sophisticated selects or joins or type-supporting\n
  9. 10.4.2009 initial release\n
  10. Paul Maritz, CEO vmware\n
  11. \n
  12. \n
  13. how fast is fast? (> 100,000 SETs per second)\n
  14. following and respecting the Big O notation (describe limiting behaviour, and classify algorithms)\n
  15. \n
  16. maintainers care and are very responsive\n
  17. \n
  18. \n
  19. brew install redis, apt packages, standard make\nport 6379\n- no major dependencies\n
  20. \n
  21. just kidding\n
  22. with lots of comments\n
  23. \n
  24. lots of clients (redis-rb, hiredis-rb, em-redis)\nnerdy DSL, but follows a logic\nCONSOLE!!!\nhttp://try.redis-db.com/\n
  25. \n
  26. slaves are read-only by default\nnon-blocking for master (logging incoming commands)\nnon-blocking for slaves (just a short switch-over)\n\n
  27. Redis Data Backup (+easier to backup, +fast recover, -may lose data, -fork() slow for bigdata)\nsave 900 1\nsave 300 10\nsave 60 10000\n
  28. Append-Only File (+readable, +faster to write, -bigger file, maybe slower if writing too often)\nrun both!\n
  29. Redis is designed to be accessed by trusted clients inside trusted environments\n-> bind to local address\n-> Auth is possible\n-> strings are not escaped in any way\n-> rename certain commands\n\n
  30. \n
  31. \n
  32. based on Redis strings\nuseful for permanent links or when urls get too long\nor to obsfuscate urls\n\n
  33. based on Redis hashes\n
  34. based on Redis hashes\n\n\n
  35. based on Redis lists (FIFO)\n
  36. based on Redis sets\n\n\n
  37. based on Redis sets with expire\n\n\n
  38. based on Redis sorted sets\nwhere you update a lot of items at once\n\n
  39. based on Redis sorted sets\nwhere you update a lot of items at once\n\n
  40. based on Redis pubsub\n
  41. based on Redis pubsub\n\n
  42. based on Redis pubsub\n\n
  43. based on Redis lists\nLTRIM makes sure the list doesn’t get longer\n\n\n
  44. based on Redis sorted set, in combi with a Hash\n\n\n\n
  45. in combination with sort\n\n\n
  46. \n
  47. \n
  48. kept in memory\n100M entries => 16GB RAM\n
  49. not seamless\n- short blockings when syncing with slaves\n- just one master\n
  50. every node has some portion of the data\n- native cluster is in the works\n- redis-rb simulates this\n
  51. don’t try to treat it that way, it’s not a replacement\n- data structures not flexible enough\n- queries not detailed enough\n
  52. DSL is unique\n
  53. \n
  54. \n
  55. \n