relational queries in Redis

Source: Internet
Author: User

This article explains how Redis preserves relational data and how it matches, ranges, and blurs queries, where the fuzzy query function is based on the latest version of 2.8.9 .

1Storage of relational data

take staff object as an example, in a relational database or similar gridgain in the memory grid product ( bottom use h2 The memory mode of the database is stored , and we save the object's data as a table. Because the memory grid is cached based on objects, there is an extra column (Staff column to save the entire object's encoding, such as the serialized binary or the Span lang= "en-US" >json format, etc., to facilitate direct return to the application after deserialization. In redis , we can use the id as a unique identifier, using the , hash , zset three data structures are saved. key-value is to save id and the entire object, determining id The scope can then be returned to the client based on it, and the other two data structures are selected for specific reasons.


2Match Query

Using the hget or hmget of a hash table can be achieved dept= ' It ' or dept in (' It ', ' QA ' This is a single-valued or multi-valued exact match query. After getting the ID list, go to query Key-value to get to the object.

3Scope Query

Because we save age as zset score,value is an ID, so you can take advantage of Zset 's The Zrangebyscore method obtains the value of score within a range of values.

4Fuzzy Query

Redis 2.8.9 after Zset added a very useful method Zrangebylex, we will save score to 0,value is name : ID format, Zrangebylex can be used to obtain the value of a letter within a range. For example,zrangebylex name [A, (F) can query out Allen, Aaron, Carter.

5Paging Query

At the same time,Zrangebylex also supports paged query, syntax similar to limit start, offset.

6Limitations

The above examples illustrate how several common queries are implemented in Redis , but Redis is only key-value storage, so there are many limitations. For example,1) A query that does not implement a multi-conditional combination, such as age>25 and name like ' A% ', requires multiple commands and computes a set or intersection for hard implementation. 2) fuzzy query Chinese more laborious:


relational queries in Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.