1: Convert the table name to the key prefix such as User:
2:2nd place the field for the Zone key--the column name corresponding to the primary key in MySQL, such as UserID
3:3rd paragraph Place primary key value, such as 2,3,4 ...., A, B, c
4:4th paragraph, write the name of the column to be stored
Users table user, convert to key-value storage |
Userid |
Username |
Passworde |
Email |
9 |
Lisi |
1111111 |
[Email protected] |
Set User:userid:9:username Lisi
Set User:userid:9:password 111111
Set user:userid:9:email [email protected]
Keys user:userid:9*
2 Note :
In the relational data, in addition to the primary key, there may be other columns also step query,
As in the above table, username is also very frequently queried, often this column is also indexed.
Converted to k-v data, a corresponding Key-value is generated for the column.
Set User:username:lisi:uid 9
In this way, we can find out userid=9 according to Username:lisi:uid,
Check User:userid:9:password/email again ...
Redis Cluster Design key