Why Use Redis instead of MongoDb for Caching? [clo

2019-03-12 12:46发布

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.

3条回答
ゆ 、 Hurt°
2楼-- · 2019-03-12 13:01

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楼-- · 2019-03-12 13:11

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.

查看更多
甜甜的少女心
4楼-- · 2019-03-12 13:16

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.

查看更多
登录 后发表回答