Advanced Redis - by Russ Smith

B044a0f039af800f4df09bf3b2465f18?s=47 Las Vegas Ruby Group
March 13, 2013
68

Advanced Redis - by Russ Smith

B044a0f039af800f4df09bf3b2465f18?s=128

Las Vegas Ruby Group

March 13, 2013
Tweet

Transcript

  1. Advanced Redis Techniques

  2. Redis is an open source, BSD licensed, advanced key-value store.

    It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
  3. the basics

  4. ca16403c13fc9 46:count":902} {KEY:VALUE} {"von:counter s:downloads:

  5. lists[milk,egg s,cereal,baco n,salt,plates, oranges,lettu

  6. {name:‘bob’,em ail:‘bob@gmail .com’,passwor d:‘password’} hashsES

  7. So what makes it different?

  8. Deep structural awareness in the storage layer.

  9. push, pop, sets, sorted sets, pub/Sub, unions, intersect, etc

  10. so what about the cool kids

  11. Resque Sidekiq Fnordmetric VON leaderboard instagram spool twitter

  12. USE the built in data structures

  13. LPUSH mylist ‘work’ LPOP mylist => ‘work’

  14. hset myhash count 0 hincrby myhash count 1 hget myhash

    count => 1
  15. zadd myzset 1 “jim” zadd myzset 2 “bob” zrange myzset

    0 -1
  16. store only what you need

  17. TWEETID:USERID

  18. USE the pipeline FOR roflscale

  19. redis.pipelined do redis.set(‘foo’, ‘bar’) redis.incr(‘baz’) end

  20. Optimize what you are storing

  21. SET user:1234 5678

  22. * 3,000,000 = 21gb

  23. HSET ‘users:100’ ‘1234’ ‘5689’

  24. * 3,000,000 = 5gb

  25. hash-max-zipmap-entries 256 hash-max-zipmap-value 1024

  26. Shard the data

  27. lpush ‘users:20130313’ ‘bob’

  28. GETting REALLY nerdy

  29. setbit activeusers:20130313 231 1 setbit activeusers:20130313 102 1

  30. devops tips

  31. Write the data to disk

  32. save 60 1000

  33. Replicate for high availability & redundancy

  34. slaveof 10.0.0.3

  35. use Sentinel for automatic failover

  36. None