Skip to content

Commit

Permalink
Fix some problems
Browse files Browse the repository at this point in the history
  • Loading branch information
OuYangJinTing committed Oct 27, 2020
1 parent d322410 commit 81674ec
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
3 changes: 0 additions & 3 deletions lib/rack/redis_throttle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
require 'redis'
require 'hiredis'
require 'redis-namespace'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/time/calculations'
require 'active_support/core_ext/date/calculations'

module Rack
module RedisThrottle
Expand Down
6 changes: 3 additions & 3 deletions lib/rack/redis_throttle/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module RedisThrottle
class Connection

def self.create(options={})
url = redis_provider || 'redis://localhost:6379/0'
options.reverse_merge!({ url: url })
client = Redis.connect(url: options[:url], driver: :hiredis)
options[:url] = redis_provider || 'redis://localhost:6379/0' unless options.has_key?(:url)
method = Redis::VERSION.to_i >= 3 ? :new : :connect
client = Redis.send(method, url: options[:url], driver: :hiredis)
Redis::Namespace.new("redis-throttle:#{ENV['RACK_ENV']}:rate", redis: client)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rack/redis_throttle/limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RedisThrottle
class Limiter < Rack::Throttle::Limiter

def initialize(app, options = {})
options.reverse_merge!({ cache: Rack::RedisThrottle::Connection.create })
options[:cache] = Rack::RedisThrottle::Connection.create(options) unless options.has_key?(:cache)
@app, @options = app, options
end

Expand Down
2 changes: 1 addition & 1 deletion redis_throttle.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'redis'
gem.add_dependency 'hiredis'
gem.add_dependency 'redis-namespace'
gem.add_dependency 'activesupport'

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
Expand All @@ -45,4 +44,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'guard-rspec'
gem.add_development_dependency 'fuubar'
gem.add_development_dependency 'growl'
gem.add_development_dependency 'activesupport'
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'mock_redis'
require 'rspec'
require 'timecop'
require 'active_support/core_ext/time/calculations'

require File.dirname(__FILE__) + '/fixtures/fake_app'

Expand Down

0 comments on commit 81674ec

Please sign in to comment.