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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With