From 51d50cc4c1e6fbf91fc53e3bd63fd34f4bc16bcc Mon Sep 17 00:00:00 2001 From: Han Date: Sun, 5 May 2013 23:51:30 -0700 Subject: [PATCH 1/2] Update README.md Added note to help users who choose Redis as their backing store not get stuck. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index bc6520a..15a8f63 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ A [Rack::Request](http://rack.rubyforge.org/doc/classes/Rack/Request.html) objec ### Throttles +*NOTE:* If you are using Redis as backing store, Redis-ActiveSupport does not recognize `1.second` so just specify the `:period` parameter in seconds. + # Throttle requests to 5 requests per second per ip Rack::Attack.throttle('req/ip', :limit => 5, :period => 1.second) do |req| # If the return value is truthy, the cache key for the return value From 2a91eb6c557e0c70f5d5e50f796747db15a5fb8e Mon Sep 17 00:00:00 2001 From: Han Chang Date: Fri, 10 May 2013 22:06:53 +0000 Subject: [PATCH 2/2] Fix #14 --- README.md | 2 -- lib/rack/attack/throttle.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 15a8f63..bc6520a 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,6 @@ A [Rack::Request](http://rack.rubyforge.org/doc/classes/Rack/Request.html) objec ### Throttles -*NOTE:* If you are using Redis as backing store, Redis-ActiveSupport does not recognize `1.second` so just specify the `:period` parameter in seconds. - # Throttle requests to 5 requests per second per ip Rack::Attack.throttle('req/ip', :limit => 5, :period => 1.second) do |req| # If the return value is truthy, the cache key for the return value diff --git a/lib/rack/attack/throttle.rb b/lib/rack/attack/throttle.rb index 4c5b1ef..29689e2 100644 --- a/lib/rack/attack/throttle.rb +++ b/lib/rack/attack/throttle.rb @@ -9,7 +9,7 @@ module Rack raise ArgumentError.new("Must pass #{opt.inspect} option") unless options[opt] end @limit = options[:limit] - @period = options[:period] + @period = options[:period].to_i end def cache