Redis IU


Published on

More for the database world

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • {}
  • Redis IU

    1. 1. Intro to NoSQL databases Redis & Mongo DB
    2. 2. Overview ➲ ● Redis What, when, why, how ➲Mongo ● ➲ DB What, when, why, how Questions
    3. 3. Redis ➲ ● ● ● What is Redis Redis is an open-source key-value data store Primarily an in-memory database Has the option of persisting data indefinitely ➲Key ● Data Structures Strings, lists, sets, hashes, sorted sets
    4. 4. Why Redis ➲Speed ● – Redis is really fast Hard to find specific numbers but I've seen claims that it's up to 5-20 times faster than traditional databases for certain applications ➲Specialized – Has highly customized tools that solves certain problems extremely well. ➲This contrasts with a traditional RDBMS that tries to be all things to all people ➲Generally seen as complimentary to a traditional RDBMS
    5. 5. When To Use Redis ➲You have to know the best type of data structure and algorithm for solving the problem you have ➲Redis publishes the Big-O notation performance numbers for all it's operations ➲If redis supports that algorithm then you'll probably want to use redis for it
    6. 6. Big O Review ➲O(1) ● ● – constant time. Fastest any algorithm can be Always takes the same amount of time ➲O(log(n)) ● ● – logarithmic time 2nd fastest time Uses a divide and conquer ➲O(n) – linear time ➲Others include ● O(n^2), O(c^n), O(n+m*log(m))
    7. 7. Using Redis ➲set x:y "{id:9000, email: ''}" ➲get x:y ➲“set” - command ➲x:y – key ➲"{id:9000, email: ''}" - value ➲By convention keys are of the form: ● z:y:x ➲But other values are allowed
    8. 8. Using Redis ➲A simple application is to use redis to count page views ● ● incr stats:page:about incrby ratings:video:1233 6
    9. 9. Mongo DB ➲MongoDB has the same concept of a database that you are familiar with ➲Within a MongoDB instance you can have zero or more databases, each acting as high-level containers for everything else. ➲A database can have zero or more collections. A collection shares enough in common with a traditional table that you can safely think of the two as the same thing. ➲Collections are made up of zero or more documents. Again, a document can safely be thought of as a row. ➲
    10. 10. Mongo DB ➲A document is made up of one or more fields, which you can probably guess are a lot like columns. ➲Indexes in MongoDB function much like their RDBMS counterparts. ➲Cursors - when you ask MongoDB for data, it returns a cursor, which we can do things to, such as counting or skipping ahead, without actually pulling down data.
    11. 11. Mongo DB ➲If ● ● ● ● Mongo is so similar to existing DBMS then why use new terminology (collection vs. table, document vs. row and field vs. column)? relational databases define columns at the table level whereas a document-oriented database defines its fields at the document level. Each document within a collection can have its own unique set of fields. A collection imposes less strict rules on a container in comparison to a table A document usually has a lot more information than a row.
    12. 12. Using Mongo ➲ ● ● ➲ ● ● The mongo CLI uses JavaScript syntax prints the list of available commands db.stats() prints the current information about your db Since Collections do not have schemas we can do the following: db.unicorns.insert({name: ’Aurora’, gender: ’f’, weight: 450}) The 'unicorns collection will be created and document with name='Aurora' will be added to it
    13. 13. Using Mongo ➲ ● ● ● Other Commands db.unicorns.find() - returns list of documents in the 'unicorns' collection "_id" : ObjectId("5239aaa9635c8909872a74fa"), "name" : "Aurora", "gender" : "f", "weight" : 450 } db.unicorns.find({gender: ’m’, weight: {$gt: 700}}) ➲db.stats() ● ➲ prints the current information about your db db.unicorns.update({name: ’Roodles’}, {weight: 590})
    14. 14. Demo ➲
    15. 15. Questions ➲