Your SlideShare is downloading. ×
The Beauty of Simplicity: Mastering Database Design with Redis
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

The Beauty of Simplicity: Mastering Database Design with Redis

9,175
views

Published on

To many on the outside, Redis looks like your average key-value store. To those in the know, Redis is a powerful data structure store that’s capable of doing much of what a full-featured database can …

To many on the outside, Redis looks like your average key-value store. To those in the know, Redis is a powerful data structure store that’s capable of doing much of what a full-featured database can handle.

In this talk, Ryan will give a quick overview of Redis’ API and the datatypes it allows you to store and query. He’ll then take you through the process of designing a complex schema with Redis and demonstrate how using simple data structures can help you in making better decisions for your applications.

Published in: Technology, Business

0 Comments
24 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
9,175
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
214
Comments
0
Likes
24
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. The Beauty of SimplicityMastering Database Design with
  • 2. What is this talk about?
  • 3. ChicagoDBhttp://chicagodb.com
  • 4. 1 2 3
  • 5. 1 2 3Basic Redis API
  • 6. 1 2 3Simple Use Cases
  • 7. 1 2 3Learning from Redis
  • 8. SET the-answer 42OK
  • 9. GET the-answer“42”
  • 10. The End
  • 11. 42 24
  • 12. http://redis.io
  • 13. ListsRPUSH primes 2(integer) 1RPUSH primes 3(integer) 2RPUSH primes 5(integer) 3
  • 14. ListsLRANGE primes 0 -11) “2”2) “3”3) “5”
  • 15. SetsSADD words foo(integer) 1SADD words bar(integer) 1SADD words foo(integer) 0
  • 16. SetsSMEMBERS words1) “foo”2) “bar”
  • 17. Sorted SetsZINCRBY words 1 foo“1”ZINCRBY words 1 bar“1”ZINCRBY words 1 foo“2”
  • 18. Sorted SetsZREVRANGE words 0 -1 WITHSCORES1) “foo”2) “2”3) “bar”4) “1”
  • 19. HashesHSET person first_name Ryan(integer) 1HSET person last_name Briones(integer) 1
  • 20. HashesHGETALL person1) “first_name”2) “Ryan”3) “last_name”4) “Briones”
  • 21. QueuesRPUSH queue foo(integer) 1RPUSH queue bar(integer) 2LPOP queue“1”
  • 22. Set IntersectionSADD fb_friends 1234567(integer) 1SADD fb_friends 1234568(integer) 1SADD purchasers 1234567(integer) 1SINTER fb_friends purchasers1) 1234567
  • 23. Chat Ser verZADD room 1307420357571.96 {:msg => “Hello Mike”}(integer) 1ZADD room 1307420462678.8 {:msg => “Hello Joe”}(integer) 1ZADD room 1307420496256.58 {:msg => “Hello World”}(integer) 1
  • 24. Chat Ser verZREVRANGE room 0 301) {...}2) {...}ZRANGEBYSCORE room 1307420357571.96 +inf1) {...}
  • 25. Application Data in Redis
  • 26. Data in RDBMSid first_name last_name login1 Ryan Briones ryanbriones... ... ... ...
  • 27. Data in RedisINCR users:uids“1”
  • 28. Data in RDBMSid first_name last_name login1 Ryan Briones ryanbriones... ... ... ...
  • 29. Data in RedisINCR users:uids“1”SET users:1:first_name RyanOKSET users:1:last_name BrionesOKSET users:1:login ryanbrionesOK
  • 30. Data in RDBMSid first_name last_name login1 Ryan Briones ryanbriones... ... ... ...
  • 31. Data in RedisKEYS users:1:*1) users:1:first_name2) users:1:last_name3) users:1:loginGET users:1:first_name“Ryan”GET users:1:last_name“Briones”GET users:1:login“ryanbriones”
  • 32. Data in RDBMSSELECT * FROM users;
  • 33. Data in RedisSADD users:all 1(integer) 1SMEMBERS users:all1) 12) ...
  • 34. Data in Redis users:uids 1users:1:first_name Ryanusers:1:last_name Briones users:1:login ryanbriones users:all {1}
  • 35. Data in RedisSET users:login:ryanbriones:uid 1OKGET users:login:ryanbriones:uid“1”
  • 36. Data in RDBMSSELECT * FROM users ORDER BY last_name DESC;
  • 37. Data in Redis users:uids 1 users:1:first_name Ryan users:1:last_name Briones users:1:login ryanbriones users:all {1}users:login:ryanbriones:uid 1
  • 38. Data in Redis SET users:last_name:Briones:uid 1001 OK SADD users_last_names Briones OK SET users:last_name:Andrews:uid 2002 OK SADD users_last_names Andrews OK SORT users_last_names ALPHA DESC BY * GET users:last_name:*:uid 1) 100 2) 200
  • 39. Data in RedisSORT users_last_names ALPHA DESC BY * GET users:last_name:*:uid STORE users_uid_by_last_name_desc(integer) 2TYPE users_uid_by_last_name_desclistLRANGE users_uid_by_last_name_desc 0 -11) 2002) 100
  • 40. Data in RedisEXPIRE users_uid_by_last_name_desc 86400(integer) 1
  • 41. Data in RDBMS id first_name last_name login 1 Ryan Briones ryanbriones ... ... ... ...id title body permalink user_id10 Redis Rocks ... redis-rocks 1... ... ... ... ...
  • 42. Data in RedisSET posts:10:title “Redis Rocks”OKSET posts:10:body “Lorem ipsum..”OKSET posts:10:permalink “redis-rocks”OKSET posts:10:user_id 1OKSET posts:permalink:redis-rocks:id 10OKSADD posts:all 10OK
  • 43. Data in RedisSET posts:10:title “Redis Rocks”OKSET posts:10:body “Lorem ipsum..”OKSET posts:10:permalink “redis-rocks”OKSET posts:10:user_id 1OKSET posts:permalink:redis-rocks:id 10OKSADD posts:all 10OKLPUSH users:1:posts 10OK
  • 44. Data in RedisSET posts:10:title “Redis Rocks”OKSET posts:10:body “Lorem ipsum..”OKSET posts:10:permalink “redis-rocks”OKSET posts:10:user_id 1OKSET posts:permalink:redis-rocks:id 10OKSADD posts:all 10OKZADD users:1:posts 1307463108973.28 10OK
  • 45. Data in RedisSORT user:1:posts DESC GET posts:*:title GET posts:*:permalink1) “Redis Rocks”2) redis-rocks
  • 46. Sharding AOF Disk Persistence Cluster/DR Lua ScriptingPub-Sub Replication Simple Transactions
  • 47. Ryan Briones@ryanbriones work for //obtiva