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

Everybody Loves Redis And So Can You!

Everybody Loves Redis And So Can You!

(This talk was presented at Steel City Ruby Conf 2012)

To call it a key-value store would be an understatement. To call it a database would be an overstatement. To call it NoSQL would be cause for defenestration. Redis, quite simply, stands on its own as a remarkable way to store data structures: strings, lists, sets, sorted sets, and hashes.

This talk will articulate the significance and elegance of its design and explore some conventional and rather unconventional ways that you can use Redis in your own applications. If you’re new to Redis, prepare to fall in love, and even if you’re already quite enamored, you’ll definitely enjoy the section about best practices and advanced usage.

Mattt Thompson

August 03, 2012
Tweet

More Decks by Mattt Thompson

Other Decks in Programming

Transcript

  1. Hashes > HMSET users:1 name Mattt > HMSET users:1 age

    25 > HMSET users:1 company Heroku
  2. Hashes > HMSET users:1 name Mattt > HMSET users:1 age

    25 > HMSET users:1 company Heroku > HKEYS users:1
  3. Hashes > HMSET users:1 name Mattt > HMSET users:1 age

    25 > HMSET users:1 company Heroku > HKEYS users:1 > HGET users:1 name
  4. Hashes user = {} user[:name] = “Mattt” user[:age] = 25

    user[:company] = “Heroku” user.keys user[:name]
  5. Hashes require ‘redis’ REDIS = Redis.new REDIS.hset “users:1”, “name”, “Mattt”

    REDIS.hset “users:1”, “age”, “25” REDIS.hset “users:1”, “company”, “Heroku”
  6. Hashes require ‘redis’ REDIS = Redis.new user = { name:

    “Mattt”, age: 25, company: “Heroku” } REDIS.hmset “users:1”, *user.flatten
  7. Lists > LPUSH fruit Apple Banana Cherry > LLEN fruit

    > LINDEX fruit 1 > LPOP fruit > RPOP fruit
  8. • _____ • H____ • L_____ • R_____ • S_____

    • Z_____ Command Naming Conventions
  9. • _____ • H____ • L_____ • R_____ • S_____

    • Z_____ • *M___ Command Naming Conventions
  10. • _____ • H____ • L_____ • R_____ • S_____

    • Z_____ • *M___ • B____ Command Naming Conventions
  11. • _____ • H____ • L_____ • R_____ • S_____

    • Z_____ • *M___ • B____ • ____X Command Naming Conventions
  12. Sets > SADD users:1:friends 2 5 7 14 23 >

    SADD users:2:friends 1 5 6 12 14 22 > SCARD users:1:friends > SISMEMBER users:2:friends 3 > SINTER users:1:friends users:2:friends
  13. Sorted Sets > ZADD numbers 1 "one" > ZADD numbers

    2 "two" > ZADD numbers 3 "three"
  14. Sorted Sets > ZADD numbers 1 "one" > ZADD numbers

    2 "two" > ZADD numbers 3 "three" > ZSCORE numbers "one"
  15. Sorted Sets > ZADD numbers 1 "one" > ZADD numbers

    2 "two" > ZADD numbers 3 "three" > ZSCORE numbers "one" > ZRANGEBYSCORE numbers -inf +inf
  16. Sorted Sets > ZADD numbers 1 "one" > ZADD numbers

    2 "two" > ZADD numbers 3 "three" > ZSCORE numbers "one" > ZRANGEBYSCORE numbers -inf +inf > ZRANGEBYSCORE numbers 1 2
  17. > MGET foo bar baz ... > SADD 1 2

    3 5 8 13 21 34 ... > HMSET users:1 k1 v1 k2 v2 ...