Home  >  Q&A  >  body text

mysql - redis和mongodb怎么结合

就是拿mongodb或mysql做存储数据库,
然后redis做缓存。
搭建好数据库之后,怎么搭建redis,让他们结合起来运用到项目中呢?
mysql+redis可以的吗?
谢谢了

迷茫迷茫2741 days ago603

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-17 15:07:19

    The question is too broad and difficult to answer;
    To put it simply, there are several points to consider when doing caching:
    1. Cache hot data. According to your own business and data structure characteristics, appropriately choose or Combine redis data structures for storage.
    2. Cache update and invalidation strategy.
    Unexpected, I will add more later.
    For example: mongodb+redis
    Mongodb can aggregate data, run cron in the background, mapReduce the data once an hour, and write the calculated data to redis for storage (it can also be directly output to mongo collection), and the front-end Query redis to get the aggregated data.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 15:07:19

    Although I represent MongoDB, the following answers may seem suspicious of Amway's own products. I still want to remind the poster to pay attention to some issues.
    Judging from the questions asked, the author is not familiar with MongoDB or Redis. I guess he came to the conclusion of using MongoDB+Redis to combine projects. I guess he read some articles? It is undeniable that in some extreme situations, adding a layer of Redis in front of MongoDB may yield certain benefits, but has the author considered his actual situation and is it really necessary to add Redis in front of MongoDB? Be aware that when a new technology is introduced, both maintenance costs and development costs, as well as the requirements for developers, will increase exponentially.
    For example, something that could be read directly from the database now needs to be considered when to read it from the cache. Correspondingly, it is necessary to consider how to refresh the cache and what to do with dirty data? These problems may not sound difficult, but no matter what the problem is, there is no simple problem in a high-concurrency environment. To put it bluntly, if the poster had enough experience to deal with the above problems, he would not raise this issue now. Fortunately, generally speaking, the concurrency of the project is not high enough to require the use of both, because MongoDB is already strong enough to cope with high concurrency and horizontal expansion capabilities.
    So regardless of other people’s opinions, the poster should think clearly about these questions: What drives you to use two technologies together, and what benefits do you want to get from it? More importantly, if only one of these technologies is used, can the problem be solved? If you don’t have enough evidence to convince yourself, you might as well test it and let the data speak for itself.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:07:19

    Nothing is wrong, reids installation is very simple, just read the official documentation

    reply
    0
  • Cancelreply