GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Redis::RateLimit(3) User Contributed Perl Documentation Redis::RateLimit(3)

Redis::RateLimit - Sliding window rate limiting with Redis

version 1.0002

    use 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

A 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.

  • Uses a sliding window for a rate limit rule
  • Multiple rules per instance
  • Multiple instances of RateLimit side-by-side for different categories of users.
  • Whitelisting/blacklisting of keys

See this excellent articles on how the sliding window rate limiting with Redis works:
  • Introduction to Rate Limiting with Redis Part 1 <http://www.dr-josiah.com/2014/11/introduction-to-rate-limiting-with.html>
  • Introduction to Rate Limiting with Redis Part 2 <http://www.dr-josiah.com/2014/11/introduction-to-rate-limiting-with_26.html>

For more information on the `weight` and `precision` options, see the second blog post above.

Port the middleware for Plack

Redis client. If none is provided, a default is constructed for 127.0.0.1:6379.

A prefix to be included on each redis key. This prevents collisions with multiple applications using the same Redis DB. Defaults to 'ratelimit'.

Set this to a true value if using a Redis client that supports transparent prefixing. Defaults to 0.

An arrayref of rules, each of which is a hashref with "interval", "limit", and optionally "precision" values.

Returns true if any of the keys are rate limited.

Returns true if any of the keys are rate limited, otherwise, it increments counts and returns false.

Returns all of the rate limiter's with prefixes removed.

Returns a list of rate limit rules violated for any of the keys, or an empty list.

Returns a list of limited keys.

Adds the keys to the whitelist so they are never rate limited.

Removes the keys from the whitelist.

Adds the keys to the blacklist so they are always rate limited.

Removes the keys from the blacklist.

Marc Mims <marc@questright.com>

This software is Copyright (c) 2016 by Marc Mims.

This is free software, licensed under:

  The MIT (X11) License
2017-08-23 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.