问题
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.
回答1:
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.
回答2:
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.
回答3:
When we say caching, speed comes to mind. The goal here is to set and retrieve something as fast as possible. In this sense, redis is faster than mongodb. However, if you find that mongodb is suitable for doing geospatial searches on cached data, it's ok to use it. You can of course invest some time and implement the same in redis, and then benchmark to see what you gain.
来源:https://stackoverflow.com/questions/10317732/why-use-redis-instead-of-mongodb-for-caching