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/

Nick Quaranto

January 12, 2012
Tweet

More Decks by Nick Quaranto

Other Decks in Programming

Transcript

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

    be swapped really stable 15/43 - 35%
  2. > set fries done OK > get fries done >

    del fries 1 > set fries done OK > expire 60 1 > get fries nil 20/43 - 47%
  3. > incr burgers 1 > incrby burgers 42 43 >

    decr burgers 42 22/43 - 52%
  4. > 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%
  5. > 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%
  6. sorted sets (zset) {key => float} atomic increments ranges by

    score or rank union/intersect 27/43 - 63%
  7. > 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%
  8. hashes {key => value} atomic increments like zset set, get,

    del, exists, len get all keys, values, or both 29/43 - 68%
  9. > 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%
  10. boggle game id, score = counter guesses, dictionary = set

    words for a game = list 33/43 - 77%
  11. 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%
  12. 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%
  13. 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%