简体   繁体   English

用Redis查询?

[英]Querying with Redis?

I've been learning Node.js so I decided to make a simple ad network, but I can't seem to decide on a database to use. 我一直在学习Node.js所以我决定建立一个简单的广告网络,但我似乎无法决定要使用的数据库。 I've been messing around with Redis but I can't seem to find a way to query the database by specific criteria, instead I can only get the value of a key or a list or set inside a key. 我一直在使用Redis,但我似乎找不到按特定条件查询数据库的方法,而是只能获取键或列表的值或设置在键内。

Am I missing something, or should I be using a more robust database like MongoDB? 我错过了什么,或者我应该使用像MongoDB这样更强大的数据库?

I would recommend to read this tutorial about Redis in order to understand its concepts and data types. 我建议阅读有关Redis的教程,以了解其概念和数据类型。 I also had problems to understand why there is no querying support similar to other (no) SQL databases until I read few articles and try to test and compare Redis with other solutions. 我也有问题要理解为什么没有类似于其他(没有)SQL数据库的查询支持,直到我阅读了一些文章并尝试测试和比较Redis与其他解决方案。 Maybe it isn't the right database for your use case, although it is very fast and supports advanced data structures, but lacks querying which is crucial for you. 也许它不是适合您的用例的数据库,虽然它非常快并且支持高级数据结构,但是缺少对您来说至关重要的查询。 If you are looking for a database which allows you to query your data then you should try mongodb or maybe riak . 如果您正在寻找一个允许您查询数据的数据库,那么您应该尝试使用mongodb或者riak

Redis is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis通常被称为数据结构服务器,因为键可以包含字符串,散列,列表,集和排序集。

If able(easy to implement) you should use these primitives(strings,hashes,lists,set and sorted sets). 如果能够(易于实现),您应该使用这些原语(字符串,散列,列表,集和排序集)。 The main advantage of Redis is that is lightning fast, but that it is rather primitive key-value store (redis is a little bit more advanced). Redis的主要优点是闪电般快,但它是相当原始的键值存储 (redis更先进一点)。 This also means that it can not be queried like for example SQL. 这也意味着无法像SQL那样queried它。

It would probably be easier to use a more advanced store, like for example Mongodb, which is a document-oriented database . 使用更高级的存储可能更容易,例如Mongodb,它是面向文档的数据库 The trade-off you make in this case is PERFORMANCE, but I believe you should only tackle that if that is becoming a problem, which it probably will not be because Mongodb is also pretty fast and has the advantage that it can be queried . 在这种情况下你做出的权衡是性能,但我相信如果这成为一个问题你应该只解决它,这可能不会是因为Mongodb也很快并且具有可以queried的优势。 I think it would be advisable to have proper indexes for your queries(read>write) to make it fast. 我认为为查询提供适当的索引 (读取>写入)以使其快速建议是可取的。

I think that the main answer comes from the data structure. 我认为主要答案来自数据结构。 Check this article about NoSQL Data Modelling, for me it was very helpful: NoSql Data Modelling . 查看关于NoSQL数据建模的这篇文章,对我来说非常有用: NoSql数据建模

A second good article ever about Data Modeling, and making a comparison between SQL and NoSQL is the following: The Relational model anti pattern . 关于数据建模的第二篇好文章,以及SQL和NoSQL之间的比较如下: 关系模型反模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM