Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Design skills of Redis key

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report