Nosql redis-mongo

4,614 views
4,422 views

Published on

These are some of my notes of my beginning, while learning Redis and Mongodb for a pet project. I made them for a tech talk at Maresme Developers Meetup #maresmedev.
Please email email me for notifying mistakes or suggestions.

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,614
On SlideShare
0
From Embeds
0
Number of Embeds
2,034
Actions
Shares
0
Downloads
32
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Nosql redis-mongo

    1. 1. NOSQLagile data storage
    2. 2. SQL: THE BEGINNING• Data structured on tables using columns• Data on one column is the key for making relationships with other tables• Normalization• RDBMS
    3. 3. SQL EXAMPLES
    4. 4. RDBMS BENEFITS• Normalization (a common standard format for accessing data)• Data consistency• Persistence• Consistency• Replication
    5. 5. RDBMS PROBLEMS
    6. 6. RDBMS PROBLEMS• Highcost on performing complex operations over a big database• High system load: scalability needs• Difficult failover recovery• Difficult denormalization
    7. 7. NOSQL TO THE RESCUE!
    8. 8. NOSQL IS...•A storage system for format free data• Web scale• Software darwinism• Different types of solutions depending on the needs: Key-value, Documents, Graphs, Objects...
    9. 9. REDIS• http://redis.io Redis is SEXY• Key-value store• In memory• Persistent (periodical asynchronous writes to disk)• All operations are atomic
    10. 10. REDISTypes of data Cool operations• Hashes • RPOPLPUSH• Sets (arrays) • Pub/Sub• Lists
    11. 11. REDISHSET myuser “email” “ivan@ivanhq.net”HSET myuser “web” “http://ibelmonte.com”HSET mysql “blog” “http://ivanh.net”HGET myuser “email”- ivan@ivanhq.net
    12. 12. REDISsadd myuser:books “jackass”sadd myuser:books “jackass2”sadd myuser:books “Dude, where’s my car?”sadd myuser:books “The hangover”smembers myuser:books1. jackass2. jackass23. Dude, where’s my car?4. The hangover
    13. 13. REDISrpush friends “John Doe”rpush friends “Foo”rpush friends “Bar”lrange friends 0 -11. John Doe2. Foo3. Bar
    14. 14. REDISrpush nonfriends “Peter Pan”rpush nonfriends “Batman”rpush nonfriends “Betty Boop”lrange nonfriends 0 -11. Peter Pan2. Batman3. Betty Boop
    15. 15. REDISrpoplpush nonfriends friendslrange friends 0 -11. John Doe2. Foo3. Bar4. Betty Booplrange nonfriends 0 -11. Peter Pan2. Batman
    16. 16. REDISPub/Sub.... a freaking AWESOME messaging queue
    17. 17. REDISPro’s:- Highly performant- Highly scalable- Interfaces available for many languages (Ruby: Ohm)Cons:- Eats your server’s memory- Manually sharding
    18. 18. MONGODB• http://mongodb.org• Document store• Writes to disk• Hight scalability• Easy sharding
    19. 19. MONGODB• Organizes data using collections• Stores documents in BSON format, a binary-encoded serialization of JSON
    20. 20. MONGODBuse usersu = { name: “ivan”, company: “Sysdivision”, age: “32” }users.insert(u)users.find();- { "_id" : ObjectId("4d5ea4e79faeda067681e214"),"name" : "ivan", company: “Sysdivision”, "age" : "32" }
    21. 21. MONGODBuse usersu = { name: “ivan”, company: “Sysdivision”, age: “32” }users.insert(u)db.users.find({name: “ivan”});- { "_id" : ObjectId("4d5ea4e79faeda067681e214"),"name" : "ivan", company: “Sysdivision”, "age" : "32" }db.users.find();db.users.find().skip(20).limit(10);
    22. 22. MONGOIDclass User include Mongoid::Document field :name field :birthday, :type => date field :money, :type => float, :default => 0.0 embeds_one :companyendclass Company field :name embedded_in :userend
    23. 23. MONGOIDuser = User.new( :name => ‘John Doe’, :birthday => ’12/7/1982’, : money => 0 )user.company.create(:name => ‘Sysdivision’)User.find(:name => ‘John Doe’)User.where(:name => /.*ohn.*/)
    24. 24. MONGOIDUser.any_of( { :name => ‘John Doe’ }, { :money.gt 10 } )User.any_in(:name => [‘John’, ‘Foo’, ‘Bar’])User.where(:name => ‘John Doe’).and(:money.gt 10)Post.all_in(:tags => [‘ruby’, ‘code’, ‘mongo’])
    25. 25. MONGODBPro’s:- Highly performant- Highly scalable- Easy sharding- Ultra powerful querying- Interfaces available for many languages (Ruby:mongo_mapper, mongoid)
    26. 26. NOSQL AWESOMENESS
    27. 27. QUESTIONS? Ivan Belmonte http://ibelmonte.com ivan@ivanhq.net

    ×