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

How to limit the Operation Frequency in Redis

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to limit the operation frequency in Redis, which is very detailed and has a certain reference value. Friends who are interested must read it!

Scene

Scenario 1

Message function limit, can only comment 10 times in 30 seconds, beyond the number of times is not allowed to comment, and prompt: too frequent

Scenario 2

The like function is limited. You can only like 10 times in 10 seconds. If you exceed the number of likes, you can no longer like it, and the operation is prohibited for 1 hour. Hint: it is too frequent and forbidden to operate for 1 hour.

Scenario 3

Upload record function, you can only upload 100 times a day. If you exceed the number of times, you are not allowed to upload any more, and prompt: beyond today's launch.

Detach the essence

In the process of business development, we constantly participate in the scheme design of various business scenarios, and it is often easy to encounter very similar scenarios, but the current business modules are different, in fact, the essence of these requirements is to solve the same problem. when we encounter this kind of scenario, we need to analyze the nature of the requirements according to our own experience and achieve a general solution. Making your solution more valuable may be different from whether you are a soulful engineer or the strongest king of cp (copy paste).

By analyzing the above three business scenarios, we can find that there is a similar logic, which is called a similar problem. Now we just want to extract this problem, design a general solution, and draw the same logic flow chart:

By analyzing the above requirements scenario, extract the conditions they all need:

Limit objects: user

Restrict operations (comments, likes, records, … )

Within the time range of X seconds

Limit the number of operands Y

Forbidden operation time Z (seconds / specific time)

Do not allow to operate again after exceeding, and prompt

(the minimum time unit is seconds: days / hours / minutes can be converted into seconds, and more scenes can be solved in seconds)

If you extract the function into a general function, is it something like this:

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