Design of the Redis key in the production environment

Source: Internet
Author: User

Question: What if we need to store the MySQL table's data in Redis?

Example: a t_user table

id username email
 11 leo  [email protected"
 22  laymans  [email protected"

If you need to store the data in the table above MySQL inside the Redis, how is the stored key designed?

Take the following steps:

    1. Get the name of the table in MySQL to prefix the key in Redis (T_user prefix)
    2. Put the name of the primary key in the MySQL table behind the prefix above, generally using colon Division (T_USER:ID)
    3. The third step of the corresponding record's primary key value as key (T_user:id:11)

Use the other fields in MySQL as the fourth part of the key t_user:id:11:xxxxxx (e.g., t_user:id:11:username)

Keep the records in the MySQL table above in redis:

get information about the user, for example, to get The information for the user id:

Design of the Redis key in the production environment

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.