|
NAMERedis::RateLimit - Sliding window rate limiting with RedisVERSIONversion 1.0002SYNOPSISuse Redis; use Redis::RateLimit; my $rules = [ { interval => 1, limit => 5 }, { interval => 3600, limit => 1000, precision => 100 }, ]; my $redis_client = Redis->new; my $limiter = Redis::RateLimit->new( redis => $redis_client, rules => $rules, ); for ( 1..10 ) { say 'Is rate limited? ', $limiter->incr('127.0.0.1') ? 'true' : 'false'; }; Output: Is rate limited? false Is rate limited? false Is rate limited? false Is rate limited? false Is rate limited? false Is rate limited? true Is rate limited? true Is rate limited? true Is rate limited? true Is rate limited? true DESCRIPTIONA Perl library for efficient rate limiting using sliding windows stored in Redis.This is a port of RateLimit.js <http://ratelimit.io/> without the non-blocking goodness. Features
BackgroundSee this excellent articles on how the sliding window rate limiting with Redis works:
For more information on the `weight` and `precision` options, see the second blog post above. TODO
ATTRIBUTESredisRedis client. If none is provided, a default is constructed for 127.0.0.1:6379.prefixA prefix to be included on each redis key. This prevents collisions with multiple applications using the same Redis DB. Defaults to 'ratelimit'.client_prefixSet this to a true value if using a Redis client that supports transparent prefixing. Defaults to 0.rulesAn arrayref of rules, each of which is a hashref with "interval", "limit", and optionally "precision" values.METHODScheck($key | \@keys)Returns true if any of the keys are rate limited.incr($key | \@keys [, $weight ])Returns true if any of the keys are rate limited, otherwise, it increments counts and returns false.keysReturns all of the rate limiter's with prefixes removed.violated_rules($key | \@keys)Returns a list of rate limit rules violated for any of the keys, or an empty list.limited_keys($key | \@keys)Returns a list of limited keys.whitelist($key | \@keys)Adds the keys to the whitelist so they are never rate limited.unwhitelist($key | \@keys)Removes the keys from the whitelist.blacklist($key | \@keys)Adds the keys to the blacklist so they are always rate limited.unblacklist($key | \@keys)Removes the keys from the blacklist.AUTHORMarc Mims <marc@questright.com>COPYRIGHT AND LICENSEThis software is Copyright (c) 2016 by Marc Mims.This is free software, licensed under: The MIT (X11) License
Visit the GSP FreeBSD Man Page Interface. |