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 3
3
require 'redis'
4
4
require 'hiredis'
5
5
require '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'
9
6
10
7
module Rack
11
8
module RedisThrottle
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ module RedisThrottle
5
5
class Connection
6
6
7
7
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 )
11
11
Redis ::Namespace . new ( "redis-throttle:#{ ENV [ 'RACK_ENV' ] } :rate" , redis : client )
12
12
end
13
13
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module RedisThrottle
5
5
class Limiter < Rack ::Throttle ::Limiter
6
6
7
7
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 )
9
9
@app , @options = app , options
10
10
end
11
11
@@ -53,7 +53,7 @@ def cache_incr(request)
53
53
begin
54
54
key = cache_key ( request )
55
55
count = cache . incr ( key )
56
- cache . expire ( key , 1 . day ) if count == 1
56
+ cache . expire ( key , 86400 ) if count == 1
57
57
count
58
58
rescue Redis ::BaseConnectionError => e
59
59
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|
30
30
gem . add_dependency 'redis'
31
31
gem . add_dependency 'hiredis'
32
32
gem . add_dependency 'redis-namespace'
33
- gem . add_dependency 'activesupport'
34
33
35
34
gem . add_development_dependency 'rake'
36
35
gem . add_development_dependency 'rspec'
@@ -45,4 +44,5 @@ Gem::Specification.new do |gem|
45
44
gem . add_development_dependency 'guard-rspec'
46
45
gem . add_development_dependency 'fuubar'
47
46
gem . add_development_dependency 'growl'
47
+ gem . add_development_dependency 'activesupport'
48
48
end
Original file line number Diff line number Diff line change 5
5
require 'mock_redis'
6
6
require 'rspec'
7
7
require 'timecop'
8
+ require 'active_support/core_ext/time/calculations'
8
9
9
10
require File . dirname ( __FILE__ ) + '/fixtures/fake_app'
10
11
You can’t perform that action at this time.
0 commit comments