我想要的不是Redis和MongoDB之间的比较。我知道它们是不同的;性能和API是完全不同的。
Redis非常快,但是API非常“原子化”。MongoDB会消耗更多的资源,但是API非常非常容易使用,我对它非常满意。
它们都很棒,我想在部署中尽可能多地使用Redis,但很难编写代码。我想在开发中尽可能多地使用MongoDB,但它需要一台昂贵的机器。
那么你认为两者的作用是什么呢?什么时候选择Redis?什么时候选择MongoDB?
我想要的不是Redis和MongoDB之间的比较。我知道它们是不同的;性能和API是完全不同的。
Redis非常快,但是API非常“原子化”。MongoDB会消耗更多的资源,但是API非常非常容易使用,我对它非常满意。
它们都很棒,我想在部署中尽可能多地使用Redis,但很难编写代码。我想在开发中尽可能多地使用MongoDB,但它需要一台昂贵的机器。
那么你认为两者的作用是什么呢?什么时候选择Redis?什么时候选择MongoDB?
当前回答
Redis和MongoDB都是非关系数据库,但它们属于不同的类别。
Redis是一个键/值数据库,它使用内存存储,这使得它非常快。它是缓存和临时数据存储(在内存中)的一个很好的候选人,因为大多数云平台(如Azure,AWS)都支持它,它的内存使用是可扩展的。但是如果您要在资源有限的机器上使用它,请考虑它的内存使用量。
另一方面,MongoDB是一个文档数据库。对于保存大型文本、图像、视频等以及几乎所有与数据库相关的内容(除了事务)来说,这是一个很好的选择。例如,如果你想开发一个博客或社交网络,MongoDB是一个合适的选择。它具有向外扩展的策略。它使用磁盘作为存储介质,因此数据将被持久化。
其他回答
也许这个资源可以帮助你在两者之间做出选择。 它还讨论了其他几个NoSQL数据库,并提供了一个简短的特征列表,以及对每个数据库的“我将使用它做什么”的解释。
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-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
如果你的项目预算允许你有足够的RAM内存在你的环境-答案是Redis。尤其是考虑到新的Redis 3.2的集群功能。
Redis. Let’s say you’ve written a site in php; for whatever reason, it becomes popular and it’s ahead of its time or has porno on it. You realize this php is so freaking slow, "I’m gonna lose my fans because they simply won’t wait 10 seconds for a page." You have a sudden realization that a web page has a constant url (it never changes, whoa), a primary key if you will, and then you recall that memory is fast while disk is slow and php is even slower. :( Then you fashion a storage mechanism using memory and this URL that you call a "key" while the webpage content you decide to call the "value." That’s all you have - key and content. You call it "meme cache." You like Richard Dawkins because he's awesome. You cache your html like squirrels cache their nuts. You don’t need to rewrite your crap php code. You are happy. Then you see that others have done it -- but you choose Redis because the other one has confusing images of cats, some with fangs.
Mongo. You’ve written a site. Heck you’ve written many, and in any language. You realize that much of your time is spent writing those stinking SQL clauses. You’re not a dba, yet there you are, writing stupid sql statements... not just one but freaking everywhere. "select this, select that". But in particular you remember the irritating WHERE clause. Where lastname equals "thornton" and movie equals "bad santa." Urgh. You think, "why don’t those dbas just do their job and give me some stored procedures?" Then you forget some minor field like middlename and then you have to drop the table, export all 10G of big data and create another with this new field, and import the data -- and that goes on 10 times during the next 14 days as you keep on remembering crap like salutation, title, plus adding a foreign key with addresses. Then you figure that lastname should be lastName. Almost one change a day. Then you say darnit. I have to get on and write a web site/system, never mind this data model bs. So you google, "I hate writing SQL, please no SQL, make it stop" but up pops 'nosql' and then you read some stuff and it says it just dumps data without any schema. You remember last week's fiasco dropping more tables and smile. Then you choose mongo because some big guys like 'airbud' the apt rental site uses it. Sweet. No more data model changes because you have a model you just keep on changing.
很难回答的问题——和大多数技术解决方案一样,这真的取决于你的情况,因为你没有描述你正在试图解决的问题,谁能提出解决方案呢?
您需要对它们进行测试,以确定其中哪一个满足您的需求。
也就是说,MongoDB不需要任何昂贵的硬件。与任何其他数据库解决方案一样,它需要更多的CPU和内存才能更好地工作,但肯定不是必需的——特别是对于早期开发目的。