Design principles of redis key

redis key design skills

1. Convert the table name to the prefix of the key eg: set book:5:title'Bible'

2. The second paragraph places the field used to distinguish the key-the column name corresponding to the primary key in mysql, such as userid

3. Place the primary key value in the third paragraph, such as 1, 2, 3, 4

4. The fourth paragraph writes the column name to be stored

for example:

set user:userid:9:username lisi

set user:userid:9:passwd 111111

Please be aware of:

In addition to the primary key in the relational database, other columns may also be queried in steps

As in the above table, username is also queried very frequently, and often such columns are also indexed. When converted to kv data, a corresponding key-value based on the column should be generated accordingly, set username:lis:userid 9 In this way, we can find out userid=9 according to username:lisi:userid, and then check the The other information of the user is fine.

This completes the operation of querying user information based on the user name.

Guess you like

Origin blog.csdn.net/weixin_42575020/article/details/113996309