Get the App
SLTechnology News&Howtos  ›  Database  › 

How to limit the Operation Frequency in Redis

Shulou Source: shulou.com Published: 2022-05-31 19:44:13 10月04日 Update

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:

Tags: Scenario limit time function solution frequency frequency logic comment frequency business hour solution problem hint essence user requirement analysis storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Docker macOS MariaDB