Skip to content

Instantly share code, notes, and snippets.

@slevine
Created January 11, 2012 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slevine/1595904 to your computer and use it in GitHub Desktop.
Save slevine/1595904 to your computer and use it in GitHub Desktop.
Comparison between Mongo and Redis

NoSQL Discussion Points

Failover

  • Master/Slave - Main Goal Data Redundancy
  • Automated Failover - High Availability
  • Good for D/R

Mongo

  • All Data is Versioned

Data Types

  • Mongo
    • JSON Style
{ author: 'joe',
  created : new Date('01/10/2012'),
  title : 'Yet another blog post',
  text : 'Here is the text...',
  tags : [ 'example', 'joe' ],
  comments : [ { author: 'jim', comment: 'I disagree' },
              { author: 'nancy', comment: 'Good post' }
  ]
}
  • Redis
    • Strings, Lists, Sets, Hashsets
    • Everything is Key/Value
    • Supports complex operations

API

  • Mongo
    • SQL Like (Native)
    • Reduce (JS)
    • Scala Support
    • Node Support
    • Supports notion of Indexs
    • Lacks Tx Support (Not an issue, b/c Akka wraps db calls in STM)

Sample Query

db.users.find({id:20202}) // Find User with id ..
db.users.find() // Find All
db.users.find({id:20202}, {first:1, last:1}) / Find first,last ...
val mongoColl = MongoConnection()("casbah_test")("test_data")
val user1 = MongoDBObject("user" -> "steve",
                          "email" -> "steve@gmail.com")
val user2 = MongoDBObject("user" -> "someOtherUser")
mongoColl += user1
mongoColl += user2
mongoColl.find()
// com.mongodb.casbah.MongoCursor =
// MongoCursor{Iterator[DBObject] with 2 objects.}

for { x <- mongoColl} yield x
/* Iterable[com.mongodb.DBObject] = List(
    { "_id" : { "$oid" : "4c3e2bec521142c87cc10fff"} ,
      "user" : "steve" ,
      "email" : "steve@gmail.com"},
     { "_id" : { "$oid" : "4c3e2bec521142c87dc10fff"} ,
      "user" : "someOtherUser"}
 ) */
  • Mongo
r.set("key", "some value")
r.get("key") // Option[String] = Some(some value)

r.hmset("hash", Map("field1" -> "1", "field2" -> 2))
r.hmget[String,String]("hash", "field1", "field2") // Option[Map[String,String]] = Some(Map(field1 -> 1, field2 -> 2))

Other

  • Mongo is Hugely Popular
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment