One millisecond after the expiration of redis, the execution of incr,key and resurrection, but the expiration time is gone, how to avoid this situation?

A scenario:
prevents users from visiting the website within a short period of time, causing pressure, and rejects requests if the number of requests is greater than 100 within 10 seconds

A key is A1, which expires after 10 seconds. During this period, A1 uses incr to add 1

every time the user visits it.

then, after the moment A1 expires, a user visits and just executes incr A1. As a result, A1 exists again, and there is no expiration time.

in this case, we are in big trouble. Is there a way to solve it?

Apr.11,2021

answer your own questions. There is no good solution at present. If you have a better solution, you are welcome to leave a message

.

the following schemes can be found in

https://blog.csdn.net/jingzi1.

https://codeshelper.com/q/10.


FUNCTION LIMIT_REQUEST_CALL(key):
current = GET(key)
IF current != NULL AND current > 100 THEN
    ERROR "too many requests"
ELSE
    value = INCR(key)
    IF value == 1 THEN
        EXPIRE(key,10)
    END
    PERFORM_API_CALL()
END
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ff76-2c4c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ff76-2c4c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?