我想要的不是Redis和MongoDB之间的比较。我知道它们是不同的;性能和API是完全不同的。

Redis非常快,但是API非常“原子化”。MongoDB会消耗更多的资源,但是API非常非常容易使用,我对它非常满意。

它们都很棒,我想在部署中尽可能多地使用Redis,但很难编写代码。我想在开发中尽可能多地使用MongoDB,但它需要一台昂贵的机器。

那么你认为两者的作用是什么呢?什么时候选择Redis?什么时候选择MongoDB?


当前回答

也许这个资源可以帮助你在两者之间做出选择。 它还讨论了其他几个NoSQL数据库,并提供了一个简短的特征列表,以及对每个数据库的“我将使用它做什么”的解释。

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

其他回答

我只是注意到这个问题已经很老了。不过,我认为以下方面值得补充:

Use MongoDB if you don't know yet how you're going to query your data. MongoDB is suited for Hackathons, startups or every time you don't know how you'll query the data you inserted. MongoDB does not make any assumptions on your underlying schema. While MongoDB is schemaless and non-relational, this does not mean that there is no schema at all. It simply means that your schema needs to be defined in your app (e.g. using Mongoose). Besides that, MongoDB is great for prototyping or trying things out. Its performance is not that great and can't be compared to Redis. Use Redis in order to speed up your existing application. Redis can be easily integrated as a LRU cache. It is very uncommon to use Redis as a standalone database system (some people prefer referring to it as a "key-value"-store). Websites like Craigslist use Redis next to their primary database. Antirez (developer of Redis) demonstrated using Lamernews that it is indeed possible to use Redis as a stand alone database system. Redis does not make any assumptions based on your data. Redis provides a bunch of useful data structures (e.g. Sets, Hashes, Lists), but you have to explicitly define how you want to store you data. To put it in a nutshell, Redis and MongoDB can be used in order to achieve similar things. Redis is simply faster, but not suited for prototyping. That's one use case where you would typically prefer MongoDB. Besides that, Redis is really flexible. The underlying data structures it provides are the building blocks of high-performance DB systems.

什么时候使用Redis?

Caching Caching using MongoDB simply doesn't make a lot of sense. It would be too slow. If you have enough time to think about your DB design. You can't simply throw in your documents into Redis. You have to think of the way you in which you want to store and organize your data. One example are hashes in Redis. They are quite different from "traditional", nested objects, which means you'll have to rethink the way you store nested documents. One solution would be to store a reference inside the hash to another hash (something like key: [id of second hash]). Another idea would be to store it as JSON, which seems counter-intuitive to most people with a *SQL-background. If you need really high performance. Beating the performance Redis provides is nearly impossible. Imagine you database being as fast as your cache. That's what it feels like using Redis as a real database. If you don't care that much about scaling. Scaling Redis is not as hard as it used to be. For instance, you could use a kind of proxy server in order to distribute the data among multiple Redis instances. Master-slave replication is not that complicated, but distributing you keys among multiple Redis-instances needs to be done on the application site (e.g. using a hash-function, Modulo etc.). Scaling MongoDB by comparison is much simpler.

何时使用MongoDB

Prototyping, Startups, Hackathons MongoDB is perfectly suited for rapid prototyping. Nevertheless, performance isn't that good. Also keep in mind that you'll most likely have to define some sort of schema in your application. When you need to change your schema quickly. Because there is no schema! Altering tables in traditional, relational DBMS is painfully expensive and slow. MongoDB solves this problem by not making a lot of assumptions on your underlying data. Nevertheless, it tries to optimize as far as possible without requiring you to define a schema.

博士TL; -如果性能是重要的,你愿意花时间优化和组织你的数据使用Redis。 -使用MongoDB,如果你需要建立一个原型,而不用担心你的DB太多。

进一步阅读:

当使用Redis作为主要数据存储时,需要考虑一些有趣的方面

也许这个资源可以帮助你在两者之间做出选择。 它还讨论了其他几个NoSQL数据库,并提供了一个简短的特征列表,以及对每个数据库的“我将使用它做什么”的解释。

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

如果你的项目预算允许你有足够的RAM内存在你的环境-答案是Redis。尤其是考虑到新的Redis 3.2的集群功能。

如果你有足够的RAM,你应该使用这两种方法。Redis和MongoDB达到了通用工具的价格。这会带来很多开销。

有一种说法是Redis比Mongo快10倍。这可能不再是真的了。MongoDB(如果我没记错的话)声称只要内存配置相同,就可以在存储和缓存文档方面击败memcache。

不管怎样。Redis不错,MongoDB也不错。如果你关心子结构并且需要聚合,那么就选择MongoDB。如果存储键和值是你主要关心的,它都是关于Redis。(或任何其他键值存储)。

我想说的是,这取决于你所在的开发团队以及你的应用程序需求。

For example, if you require a lot of querying, that mostly means it would be more work for your developers to use Redis, where your data might be stored in variety of specialized data structures, customized for each type of object for efficiency. In MongoDB the same queries might be easier because the structure is more consistent across your data. On the other hand, in Redis, sheer speed of the response to those queries is the payoff for the extra work of dealing with the variety of structures your data might be stored with.

MongoDB为具有传统DB和SQL经验的开发人员提供了简单、更短的学习曲线。然而,Redis的非传统方法需要更多的努力去学习,但更大的灵活性。

如。缓存层可能在Redis中可以更好地实现。对于更多可模式的数据,MongoDB更好。[注:MongoDB和Redis在技术上都是无模式的]

如果你问我,我个人对大多数需求的选择是Redis。

最后,我希望你现在已经看到http://antirez.com/post/MongoDB-and-Redis.html