Redis - An Introduction

3,114 views

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
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,114
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
54
Comments
0
Likes
5
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\n...like 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!!!\nhttp://try.redis-db.com/\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 Sharesight.co.nz WellRailed 23/05/2012 http://www.flickr.com/photos/linecon0/1085617988
    2. 2. https://github.com/plataformatec/devise/issues/1856
    3. 3. What isRedis?http://www.flickr.com/photos/spisharam/2742433355/
    4. 4. key-value store http://www.flickr.com/photos/jamesclay/2312912612/
    5. 5. memcached on steroids
    6. 6. no document database http://www.flickr.com/photos/linneberg/4481309196/
    7. 7. no relational database http://www.flickr.com/photos/lencioni/203030529/
    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 http://www.flickr.com/photos/gjw/487364375/
    12. 12. It’s incredibly fast!
    13. 13. Craftmanship http://www.flickr.com/photos/gte491n/4335439637/
    14. 14. LoveNot like this guy... http://www.flickr.com/photos/brettmorrison/4718717523/
    15. 15. Alive and kicking +
    16. 16. Well documented
    17. 17. Easy to install
    18. 18. Easy to configure http://www.flickr.com/photos/mag3737/3176598270/
    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/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
    21. 21. or on-the-fly$ redis-cliCONFIG SET loglevel debug
    22. 22. Easy to usehttp://www.flickr.com/photos/derekgavey/4243329714/
    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. http://www.flickr.com/photos/takkaria/2520731995/Use Cases
    29. 29. Cache Store https://github.com/jodosha/redis-storeSession Store https://github.com/mattmatt/redis-session-storeCounters 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 https://github.com/defunkt/resque Sidekiq https://github.com/mperham/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: ... author: ... set set tag:redis tag:rails 1 2 3
    44. 44. Queue-activated shell scripts
    45. 45. Limits & drawbacks http://www.flickr.com/photos/36117591@N04/3558894634/
    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 readingshttp://redis.io
    52. 52. RailsConf 2012http://www.youtube.com/watch?v=VOFTop3AMZ8
    53. 53. Thank you! Thorsten Böttger @enebo http://mt7.dehttp://www.flickr.com/photos/analogian/5913840143/ http://Sharesight.co.nz

    ×