The relationship query in Redis

Source: Internet
Author: User
Tags redis

In this paper, Redis How to save relational data, and how to match, scope, fuzzy query For example, fuzzy query function is based on the latest 2.8.9 version. 1 Storage of relational data

Take the staff object as an example, in a relational database or a similar Gridgain memory grid product (the underlying use of the H2 database in memory mode storage), we save the object's data in a table Form. Because the memory grid is cached based on objects, an extra column (staff column) is used to save the entire object's encoding, such as a serialized binary or JSON format, which facilitates direct return to the application for deserialization. In Redis, we can use ID as the unique identification, using key-value, hash, zset three kinds of data structure to save. Key-value is to save the ID and the entire object, determine the ID range can be based on it to return the object to the client, and choose the other two data structure of the specific reasons behind.


2 Matching query

The hget or hmget of a hash table can be used to achieve a single or multivalued exact matching query dept= ' it ' or dept in (' It ', ' QA '). Get the ID list, then go to the query Key-value get to the object. 3 Range Query

Because we save the age as a Zset score,value is an ID, we can use the Zset Zrangebyscore method to get the value of score in a range of intervals. 4 Fuzzy Query

Redis 2.8.9 after Zset added a very useful method Zrangebylex, we will save score is the name: ID format, using 0,value can get letters in a range of value values. For example, Zrangebylex name [A, (F), you can query Allen, Aaron, Carter. 5 pagination Query

At the same time,Zrangebylex also supports paging queries, syntax similar to limit start, offset. 6 Limitations

The above examples illustrate several common queries in the Redis implementation, but redis after all just key-value storage, so there are many limitations. For example, 1 cannot implement a multiple-conditional combination of queries, such as AGE>25 and name like ' a% ', which requires more than one command to implement and compute the set or intersection. 2 Fuzzy query Chinese more laborious:


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.