Why Use Redis instead of MongoDb for Caching?

jfountain picture jfountain · Apr 25, 2012 · Viewed 13.7k times · Source

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.

Answer

Tyler Brock picture Tyler Brock · Apr 25, 2012

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.