Project

bottleneck

0.0
No commit activity in last 3 years
No release in over 3 years
Simple Redis based Rate Limiter for Rails applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.6
~> 10.0
~> 6.0
~> 3.0
~> 0.52.1

Runtime

 Project Readme

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.