Simple Redis based rate limiter for Rails
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
config
lib
spec
.gitignore
.rspec
.rubocop.yml
.travis.yml
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
bottleneck.gemspec

README.md

Build Status

Bottleneck

Bottleneck - simple Redis based requests limiter.

Installation

Add this line to your application's Gemfile:

gem 'bottleneck'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bottleneck

Usage

Create two yaml files in config dir:

bottleneck.yml

limits:
  time_period_seconds: 3600
  max_requests_count: 100

redis.yml

host: 'localhost'
port: 6379

Add before action to your controller:

class ApplicationController < ActionController::API
  before_action :check_limit

  private

  def check_limit
    result = Bottleneck.check(request.remote_ip)
    render status: result[:status], json: { message: result[:message] }
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/maratgaliev/bottleneck.

License

The gem is available as open source under the terms of the MIT License.