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:
- Get the name of the table in MySQL to prefix the key in Redis (T_user prefix)
- Put the name of the primary key in the MySQL table behind the prefix above, generally using colon Division (T_USER:ID)
- 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