CodePudding user response:
Using Redis INCR atoms on the properties, the key value of IP, is valid for 1 minuteSuppose to access, IP - 1 from the value of the cache out incr is less than 100 release, greater than 100 is wrong
CodePudding user response:
Use redis String for storage, IP as the Key, the value with the method of setting value, after each set out the return value is the increase of value, if the limits to 100, to the set a timeout for 1 minute, the Key will be automatically disappear in a minuteCodePudding user response:
False:
$isKey=EXISTS rate. Limiting: $IP
If $isKey is 1
$times=INCR rate. Limiting: $IP
If $times & gt; 100//100 visit will increase to 101
Throw//access frequency more than limit, throw an exception
The exit
The else
MULTI//here, if not add transaction, race conditions possible
INCR rate. Limiting: $IP
The EXPIRE $keyName, 60
The EXEC