Redis Cache Data Table

Source: Internet
Author: User

Visually, the data in the database is stored on a table, and more microscopically, the tables are stored on a row. Each execution of a
Secondary select query, the database returns a result set that consists of several rows. So, a natural
The idea is to find a data structure in Redis that corresponds to the database L row. Five basic data structures are available in Redis
, which is a string, a list, a hash (hash), a collection (set), and an ordered set (sorted
Set). After investigation, it is found that there are two kinds of data structures suitable for storing rows, namely, string and hash.
To put the row data of a database into a string, you first need to format the row data. In fact, the result set
Each row can be seen as a collection of key-value pairs consisting of field names and their corresponding values. This key-value pair structure makes it easy for us
Think of JSON format. Therefore, the JSON format is chosen as the format template for each row of the result set. According to this idea, I
You can format the result set as several JSON objects and convert the JSON object to a string into a redis.

The process of storing data in a database is much more intuitive than storing it in string. This is the structural nature of the hash

The--hash itself is a set of key-value pairs: A "Parent key" contains a number of "subkeys", each "sub-key"

Key "corresponds to a value. According to the previous analysis, each row in the result set is actually a set of key-value pairs. Use
The Redis key-value pair collection represents the database key-value pair collection should be more appropriate: for a row in the result set, the field corresponds
In the hash "sub-key", the value of the field is the hash "sub-key" corresponding to the value, that is, the result set of one row corresponds to a
Hash

Redis Hash is a string-type field and value mapping table. A key can correspond to more than one field, and one field corresponds to a value. Storing an object as a hash type can save memory more than storing each field as a string type.

Redis Cache Data Table

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.