Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An introduction to Relational query in redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today's editor to share with you is about the introduction of the relationship query in redis, many people do not know much about it, in order to let you know more about the relationship query in redis, so to summarize the following content, let's look down together. I'm sure you'll get something.

This paper gives an example of how Redis saves relational data, and how to match, scope and fuzzy query.

1. Storage of relational data

In the case of Staff objects, in relational databases or GridGain-like in-memory grid products (underlying using the in-memory mode storage of H2 databases), we hold the object's data in table form. Because the memory grid is cached based on objects, an additional column (Staff column) is added to store the encoding of the entire object, such as serialized binary or JSON format, so that it can be returned directly to the application for deserialization.

In Redis, we can use id as the unique identity and use key-value, hash and zSet data structures to save. Key-value is to save the id and the entire object, and after determining the scope of the id, the object can be returned to the client.

2. Matching query

Single-valued or multi-valued exact matching queries such as dept='IT' or dept in ('IT',' QA') can be realized by using hget or hmget of hash table. After getting the id list, query key-value to get the object.

3. Scope query

Because the score,value that we save age as zSet is id, we can use zSet's zrangeByScore method to get the value of score in a certain range.

4. Fuzzy query

After Redis 2.8.9, zSet added a very useful method, zrangeByLex. We save score as 0MagneValue is the name: id format. Using zrangeByLex, we can get the value of letters in a certain range. For example, zrangeByLex name [A, (F, you can query out Allen, Aaron, Carter.

5. Paging query

At the same time, zrangeByLex also supports paged queries with syntax similar to limit start and offset.

6. Limitations

The above examples illustrate the implementation of several common queries in Redis, but after all, Redis is only key-value storage, so it has many limitations.

For example:

1) it is impossible to implement a query with a combination of multiple conditions, such as age > 25 AND name like'A% query. If you want to implement it, you need multiple commands and compute union or intersection.

2) Fuzzy query in Chinese is more difficult.

These are the details of the introduction of relational queries in redis. Have you learned anything after reading them? If you want to know more about it, welcome to the industry information!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report