A rate limiting client using Redis.
Follow the instructions in our manual to add our package repository and then run the below command.
apt-get install halon-extras-rate-redis
yum install halon-extras-rate-redis
This HSL module requires that the redis plugin is installed.
These functions needs to be imported from the extras://rate-redis
module path.
Check or account for the rate of entry
in namespace
during the last interval
. On error an exception is thrown.
Params
- namespace
string
- The namespace - entry
string
- The entry - count
number
- The count - interval
number
- The interval in seconds - options
array
- The options- profile
string
- Theredis
plugin config profile
- profile
Returns
If count
is greater than zero, it will increase the rate and return true
, or return false
if the limit is exceeded. If count is zero (0
), it will return the number of items during the last interval
.
Example
import { rate_fixed_window as rate } from "extras://rate-redis";
if (rate("outbound", $connection["auth"]["username"], 3, 60) == false) {
Reject("User is only allowed to send 3 messages per minute");
}
Works the same as the rate
function but uses a sliding window instead of a fixed window.