Get the App
SLTechnology News&Howtos  ›  Database  › 

Design skills of Redis key

Shulou Source: shulou.com Published: 2022-06-01 21:23:12 10月03日 Update

Design skills of Redis key

1: convert the table name to a key prefix such as tag:

2: paragraph 2 places the field for the partition key-- the column name corresponding to the primary key in the mysql, such as userid

3: paragraph 3 places primary key values, such as 2, 3, 4, a, b, c

4: paragraph 4, write the column name to be stored

User table user, converted to key-value storage

Userid

Username

Passworde

Email

nine

Lisi

1111111

Lisi@163.com

Set user:userid:9:username lisi

Set user:userid:9:password 111111

Set user:userid:9:email lisi@163.com

Keys user:userid:9*

(when distributed, you can hash to one server at the same time)

However, how to query with a user name? Is that so?

So, the best way is to: redundant design:

Set user:username:lisi:uid 9

(find 9 according to user:username:lisi:uid, and then find other information based on 9)

2 Note:

In relational data, it is possible to query other columns in addition to the primary key.

As in the above table, username is also queried very frequently, and often this column is indexed.

If you convert it to the kmurv data, a key-value based on this column should be generated accordingly.

Set user:username:lisi:uid 9

In this way, we can find out the userid=9 according to username:lisi:uid.

Check user:9:password/email again.

Tags: Query design data user storage skill frequent table above information redundancy distributed prefix method at the same time field time best server step user name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno MariaDB Shulou Technology Shulou Information