From de3bb6cc15f870b9fd7be346dc00ce0032ddd976 Mon Sep 17 00:00:00 2001 From: OuYangJinTing <2729877005qq@gmail.com> Date: Tue, 27 Oct 2020 16:32:27 +0800 Subject: [PATCH] Fix some problems --- lib/rack/redis_throttle.rb | 3 --- lib/rack/redis_throttle/connection.rb | 6 +++--- lib/rack/redis_throttle/limiter.rb | 2 +- redis_throttle.gemspec | 2 +- spec/spec_helper.rb | 1 + 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/rack/redis_throttle.rb b/lib/rack/redis_throttle.rb index d96ca6f..e1d6fdb 100644 --- a/lib/rack/redis_throttle.rb +++ b/lib/rack/redis_throttle.rb @@ -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 diff --git a/lib/rack/redis_throttle/connection.rb b/lib/rack/redis_throttle/connection.rb index cd4667c..96a8711 100644 --- a/lib/rack/redis_throttle/connection.rb +++ b/lib/rack/redis_throttle/connection.rb @@ -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 diff --git a/lib/rack/redis_throttle/limiter.rb b/lib/rack/redis_throttle/limiter.rb index 7c1bf58..383187e 100644 --- a/lib/rack/redis_throttle/limiter.rb +++ b/lib/rack/redis_throttle/limiter.rb @@ -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 diff --git a/redis_throttle.gemspec b/redis_throttle.gemspec index f3cef09..08e875c 100644 --- a/redis_throttle.gemspec +++ b/redis_throttle.gemspec @@ -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' @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 43b4f07..db43473 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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'