Skip to content

Commit

Permalink
consolidate Redis initialzation to one place (#4182)
Browse files Browse the repository at this point in the history
  • Loading branch information
omgitsbillryan authored Apr 24, 2020
1 parent 0a6be4b commit c033583
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 9 deletions.
File renamed without changes.
4 changes: 1 addition & 3 deletions config/initializers/breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
require 'evss/letters/service'

# Read the redis config, create a connection and a namespace for breakers
redis_config = Rails.application.config_for(:redis).freeze
redis = Redis.new(redis_config[:redis])
redis_namespace = Redis::Namespace.new('breakers', redis: redis)
redis_namespace = Redis::Namespace.new('breakers', redis: Redis.current)

services = [
Appeals::Configuration.instance.breakers_service,
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class Rack::Attack
REDIS_CONFIG = Rails.application.config_for(:redis).freeze
Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new(Redis.new(REDIS_CONFIG[:redis]))
Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new(Redis.current)

throttle('example/ip', limit: 1, period: 5.minutes) do |req|
req.ip if req.path == '/v0/limited'
Expand Down
4 changes: 0 additions & 4 deletions rakelib/connectivity.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
# Allows running on development machines
Rails.logger = Logger.new(STDOUT)

# For Rx/SM
REDIS_CONFIG = Rails.application.config_for(:redis).freeze
Redis.current = Redis.new(REDIS_CONFIG[:redis])

class ConnectivityError < StandardError; end

# Convenience function that runs a connectivity example and prints out
Expand Down

0 comments on commit c033583

Please sign in to comment.