Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Use Redis instead of MongoDb for Caching? [closed]

I've seen many people using Redis as a cache lately, why not Mongo? As far as I could tell Redis can set an expire date on an index, like memcache but otherwise are there any reasons not to use Mongo for this?

I ask as I'm doing a large join in MySQL and then changing the data after selecting it. I'm already using memcache on other parts of the site but saving this in Mongo would allow me to do geospatial searches on the cached data.

like image 512
jfountain Avatar asked Apr 25 '12 14:04

jfountain


People also ask

Why we use Redis for caching why we not use MongoDB for caching?

Redis stores data in-memory using various key values. It excels over MongoDB when working with rapidly changing data, but because most of that data needs to fit in memory, you need a foreseeable database size.

Why Redis is better than MongoDB?

Speed: Redis is faster than MongoDB because it's an in-memory database. RAM: Redis uses more RAM than MongoDB for non-trivial data sets. Scalability: MongoDB scales better than Redis. Storage: Businesses (primarily) use Redis for key-value storage.

Why is Redis good for caching?

Redis employs a primary-replica architecture and supports asynchronous replication where data can be replicated to multiple replica servers. This provides improved read performance (as requests can be split among the servers) and faster recovery when the primary server experiences an outage.

Is MongoDB good for caching?

Does MongoDB handle caching? Yes. MongoDB keeps most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.


2 Answers

A lot of people do use MongoDB for a low-medium grade cache and it works just great.

Because it offers more functionality than a simple key value store via ad-hoc queryability it isn't as pure of a caching layer as a memcache or redis (it can be slower to insert and retrieve data).

Extremely high performance is attainable (the working set is in RAM after all), but the data model is heavier.

However, on the flip side, MongoDB does offer a persistance layer that makes a lot more sense (to most developers) for the type of data that is most likely needed at a later time, unlike Redis.

like image 143
Tyler Brock Avatar answered Sep 20 '22 03:09

Tyler Brock


The biggest difference between MongoDB and Redis is that Redis usually stores the entire database in memory. MongoDB uses a memory mapped file to pretend everything is in memory, and lets the OS page bits in and out of disk as necessary. If the OS can keep everything in memory, performance will be somewhat similar.

like image 22
Joshua Martell Avatar answered Sep 24 '22 03:09

Joshua Martell