Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redis: Data Cheeseburgers

Redis: Data Cheeseburgers

A short introduction to Redis.

Definitely check out v2 of this talk! http://speakerdeck.com/u/qrush/p/redis-data-cheeseburgers-2

Given at BarCampRochester3 in 2010. http://barcamproc.org/

Eb8975af8e49e19e3dd6b6b84a542e26?s=128

Nick Quaranto

January 12, 2012
Tweet

Transcript

  1. Redis Data Cheeseburgers

  2. Redis Data Cheeseburgers 1/43 - 3%

  3. Nick Quaranto 2/43 - 5%

  4. 3/43 - 7%

  5. rubygems.org 4/43 - 10%

  6. @qrush nick@quaran.to litanyagainstfear.com 5/43 - 12%

  7. Redis 6/43 - 14%

  8. no 7/43 - 17%

  9. yes 8/43 - 19%

  10. persist data as you think of it 9/43 - 21%

  11. LRANGE 0 -1 basics data types use cases 10/43 -

    24%
  12. basics 11/43 - 26%

  13. history 12/43 - 28%

  14. installing 13/43 - 31%

  15. drivers ruby python java php node.js ... 14/43 - 33%

  16. memory keys, values keys must stay in memory values can

    be swapped really stable 15/43 - 35%
  17. speed ANSI C 110,000 SETs/second 81,000 GETs/second pipelining 16/43 -

    38%
  18. misc 17/43 - 40%

  19. data types 18/43 - 42%

  20. strings like memcached simple data expiration renaming multiple get/set 19/43

    - 45%
  21. > set fries done OK > get fries done >

    del fries 1 > set fries done OK > expire 60 1 > get fries nil 20/43 - 47%
  22. counters incr incrby decr decrby completely atomic 21/43 - 49%

  23. > incr burgers 1 > incrby burgers 42 43 >

    decr burgers 42 22/43 - 52%
  24. lists push/pop length random access ranges 23/43 - 54%

  25. > rpush order burger 1 > rpush order hotdog 2

    > rpush order fries 3 > lrange order 0 -1 1. burger 2. hotdog 3. fries > lpop order burger > rpop order fries > lindex order 0 hotdog 24/43 - 56%
  26. sets unique elements basic functionality from lists intersect union difference

    25/43 - 59%
  27. > sadd meat bacon 1 > sadd meat turkey 1

    > sadd toppings bacon 1 > sadd toppings bacon 0 > sinter meat toppings 1. bacon > sdiff meat toppings 1. turkey 26/43 - 61%
  28. sorted sets (zset) {key => float} atomic increments ranges by

    score or rank union/intersect 27/43 - 63%
  29. > zadd menu 4.99 burger 1 > zadd menu 2.99

    shake 1 > zadd menu 1.99 fries 1 > zrank menu fries 0 > zscore menu fries 1.99 > zrange menu 0 -1 1. fries 2. shake 3. burger > zrangebyscore menu 2 5 1. shake 2. burger > zremrangebyscore menu 2 5 28/43 - 66%
  30. hashes {key => value} atomic increments like zset set, get,

    del, exists, len get all keys, values, or both 29/43 - 68%
  31. > hset orders nick burger 1 > hset orders john

    fries 1 > hget orders nick burger > hvals orders 1. burger 2. fries > hgetall orders 1. nick 2. burger 3. john 4. fries 30/43 - 70%
  32. use cases 31/43 - 73%

  33. boggle 32/43 - 75%

  34. boggle game id, score = counter guesses, dictionary = set

    words for a game = list 33/43 - 77%
  35. def load $redis.del "dict" dict = File.read("/usr/share/dict/words" dict.split.each do |word|

    if word =~ /^[a-z]{3,8}$/ $redis.sadd "dict", word.upcase end end end def word?(word) $redis.sismember("dict", word) end 34/43 - 80%
  36. queues 35/43 - 82%

  37. queues 36/43 - 84%

  38. analytics 37/43 - 87%

  39. analytics: gem downloads 38/43 - 89%

  40. on a gem download $redis.incr "downloads" $redis.incr "downloads:rubygem:rails" key =

    "downloads:version:rails-2.3.5" $redis.incr key $redis.zincrby "downloads:today", 1, key 39/43 - 91%
  41. daily rollover date = "2010-04-02" $redis.rename "dls:today", "dls:yesterday" dls =

    Hash[*$redis.zrange("dls:yesterday", 0, -1, "withscores")] dls.each do |key, score| ver = versions[key] $redis.hincrby ver, date, score $redis.hincrby ver.rubygem, date, score end 40/43 - 94%
  42. wrapup 41/43 - 96%

  43. redis is... really damn fast extremely useful waiting for you!

    42/43 - 98%