Redis - An Introduction


Published on

This talk gives an introduction into what Redis is, what you can do with it and why it is cool.

Published in: Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Kiwi accent, still lose me on the phone\n#bedrooms instead of square meters\nThanks, Driver!\n
  • Salvatore Sanfilippo, Pieter Noordhuis, Paul Maritz, Jose Valim, DHH\nthey have something in common\n
  • \n
  • \n
  • NoSQL, REmote DIctionary Server, written in C, single-threaded, all data in memory\n\ memcached\n
  • advanced data structures\npersistence\n
  • supports advanced data structures\nbut not THAT advanced \n
  • set-based queries, but not with that highly sophisticated selects or joins or type-supporting\n
  • 10.4.2009 initial release\n
  • Paul Maritz, CEO vmware\n
  • \n
  • \n
  • how fast is fast? (> 100,000 SETs per second)\n
  • following and respecting the Big O notation (describe limiting behaviour, and classify algorithms)\n
  • \n
  • maintainers care and are very responsive\n
  • \n
  • \n
  • brew install redis, apt packages, standard make\nport 6379\n- no major dependencies\n
  • \n
  • just kidding\n
  • with lots of comments\n
  • \n
  • lots of clients (redis-rb, hiredis-rb, em-redis)\nnerdy DSL, but follows a logic\nCONSOLE!!!\n\n
  • \n
  • slaves are read-only by default\nnon-blocking for master (logging incoming commands)\nnon-blocking for slaves (just a short switch-over)\n\n
  • 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
  • Append-Only File (+readable, +faster to write, -bigger file, maybe slower if writing too often)\nrun both!\n
  • 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
  • \n
  • \n
  • based on Redis strings\nuseful for permanent links or when urls get too long\nor to obsfuscate urls\n\n
  • based on Redis hashes\n
  • based on Redis hashes\n\n\n
  • based on Redis lists (FIFO)\n
  • based on Redis sets\n\n\n
  • based on Redis sets with expire\n\n\n
  • based on Redis sorted sets\nwhere you update a lot of items at once\n\n
  • based on Redis sorted sets\nwhere you update a lot of items at once\n\n
  • based on Redis pubsub\n
  • based on Redis pubsub\n\n
  • based on Redis pubsub\n\n
  • based on Redis lists\nLTRIM makes sure the list doesn’t get longer\n\n\n
  • based on Redis sorted set, in combi with a Hash\n\n\n\n
  • in combination with sort\n\n\n
  • \n
  • \n
  • kept in memory\n100M entries => 16GB RAM\n
  • not seamless\n- short blockings when syncing with slaves\n- just one master\n
  • every node has some portion of the data\n- native cluster is in the works\n- redis-rb simulates this\n
  • 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
  • DSL is unique\n
  • \n
  • \n
  • \n
  • Redis - An Introduction

    1. 1. Redis Thorsten Böttger WellRailed 23/05/2012
    2. 2.
    3. 3. What isRedis?
    4. 4. key-value store
    5. 5. memcached on steroids
    6. 6. no document database
    7. 7. no relational database
    8. 8. Salvatore Sanfilippo Pieter Noordhuis
    9. 9. Open Source
    10. 10. design principle“I see Redis definitely more as a flexible tool thanas a solution specialized to solve a specificproblem.” — Salvatore Sanfilippo
    11. 11. Characteristics
    12. 12. It’s incredibly fast!
    13. 13. Craftmanship
    14. 14. LoveNot like this guy...
    15. 15. Alive and kicking +
    16. 16. Well documented
    17. 17. Easy to install
    18. 18. Easy to configure
    19. 19. XML
    20. 20. 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/ when daemonized.daemonize no# When running daemonized, Redis writes a pid file in /var/run/ by# default. You can specify a custom pid file location here.pidfile /var/run/ 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 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
    21. 21. or on-the-fly$ redis-cliCONFIG SET loglevel debug
    22. 22. Easy to use
    23. 23. Administration
    24. 24. Replication Master Slave Slave SlaveSlave Slave
    25. 25. Persistence Redis Data Backup RedisRedis Redis Redis Redis time
    26. 26. Persistence Append-Only File Redis∂ ∂ ∂ ∂ time
    27. 27. Security
    28. 28. Cases
    29. 29. Cache Store Store stats, API requests per hour, DoS, Spam
    30. 30. Url Shortener Redis string a6hz89z: https://mysite/ a/very/deep/ link? with=params
    31. 31. Wizards RedisForm Step 1 hash a: ‘name’ b: ‘email’Form Step 2 after 3rd step intermediate results ... DB k: ...Form Step 3
    32. 32. Map-Reduce Redis hash Worker sums[a]Map { Worker sums[b] sums[c] } Reduce Worker
    33. 33. Job Queue Redis listRails App Push now 1.hour.ago ... 2.hours.ago Pop Worker Resque Sidekiq
    34. 34. Unique Visitors Redis set user A user K user Y
    35. 35. List of online users Redis set ⌚ user A ⌚ user K ⌚ user Y
    36. 36. Todo lists Redis sorted set 1. this 2. that 3. ...
    37. 37. Leaderboard Redis sorted set 7. top 3. middle 1. loser
    38. 38. Push Notifications RedisEvent pubsub channel AEvent Publish channel B Pusher Subscribe ...Event
    39. 39. Chat system Redis pubsub Publish channel A Subscribe Subscribe Publishuser A channel B user B
    40. 40. Communication between Apps Redis pubsubRails Publish channel A Subscribe Any Subscribe Publish other channel B
    41. 41. Activity Feed Redisaction list } A wrote B is following display A added LTRIM A wrote
    42. 42. Activity Feed 2where 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’
    43. 43. Tagging Redis hash hash hashbook_1 book_2 book_2name: ... name: ... name: ... author: ... author: ... set set tag:redis tag:rails 1 2 3
    44. 44. Queue-activated shell scripts
    45. 45. Limits & drawbacks
    46. 46. Big Data
    47. 47. Scalability
    48. 48. To the rescue: Clustering Master Master Master consistent Master Master hashing Master Master Master
    49. 49. It’s not a Database
    50. 50. Not Exchangeable
    51. 51. Further readings
    52. 52. RailsConf 2012
    53. 53. Thank you! Thorsten Böttger @enebo http://mt7.de