File tree Expand file tree Collapse file tree 5 files changed +7
-9
lines changed Expand file tree Collapse file tree 5 files changed +7
-9
lines changed Original file line number Diff line number Diff line change 33require 'redis'
44require 'hiredis'
55require 'redis-namespace'
6- require 'active_support/core_ext/hash/reverse_merge'
7- require 'active_support/core_ext/time/calculations'
8- require 'active_support/core_ext/date/calculations'
96
107module Rack
118 module RedisThrottle
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ module RedisThrottle
55 class Connection
66
77 def self . create ( options = { } )
8- url = redis_provider || 'redis://localhost:6379/0'
9- options . reverse_merge! ( { url : url } )
10- client = Redis . connect ( url : options [ :url ] , driver : :hiredis )
8+ options [ : url] = redis_provider || 'redis://localhost:6379/0' unless options . has_key? ( :url )
9+ method = Redis :: VERSION . to_i >= 3 ? :new : :connect
10+ client = Redis . send ( method , url : options [ :url ] , driver : :hiredis )
1111 Redis ::Namespace . new ( "redis-throttle:#{ ENV [ 'RACK_ENV' ] } :rate" , redis : client )
1212 end
1313
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module RedisThrottle
55 class Limiter < Rack ::Throttle ::Limiter
66
77 def initialize ( app , options = { } )
8- options . reverse_merge! ( { cache : Rack ::RedisThrottle ::Connection . create } )
8+ options [ :cache ] = Rack ::RedisThrottle ::Connection . create ( options ) unless options . has_key? ( :cache )
99 @app , @options = app , options
1010 end
1111
@@ -53,7 +53,7 @@ def cache_incr(request)
5353 begin
5454 key = cache_key ( request )
5555 count = cache . incr ( key )
56- cache . expire ( key , 1 . day ) if count == 1
56+ cache . expire ( key , 86400 ) if count == 1
5757 count
5858 rescue Redis ::BaseConnectionError => e
5959 puts "ERROR: Redis connection not available. Rescuing cache.incr(key)" if ENV [ 'DEBUG' ]
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
3030 gem . add_dependency 'redis'
3131 gem . add_dependency 'hiredis'
3232 gem . add_dependency 'redis-namespace'
33- gem . add_dependency 'activesupport'
3433
3534 gem . add_development_dependency 'rake'
3635 gem . add_development_dependency 'rspec'
@@ -45,4 +44,5 @@ Gem::Specification.new do |gem|
4544 gem . add_development_dependency 'guard-rspec'
4645 gem . add_development_dependency 'fuubar'
4746 gem . add_development_dependency 'growl'
47+ gem . add_development_dependency 'activesupport'
4848end
Original file line number Diff line number Diff line change 55require 'mock_redis'
66require 'rspec'
77require 'timecop'
8+ require 'active_support/core_ext/time/calculations'
89
910require File . dirname ( __FILE__ ) + '/fixtures/fake_app'
1011
You can’t perform that action at this time.
0 commit comments