diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-03 23:18:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-03 23:18:13 +0200 |
commit | c997091166ba1801eea3a587c913b020b9b84ce4 (patch) | |
tree | ed109c440d11133421f3b2187c71b1c4e0270c6e /config/initializers | |
parent | 005f1fd360ada23c6e35c6cc1fd06b7a4fe28c41 (diff) |
Clean up redis configuration. Allow using REDIS_URL to set advanced (#2732)
connection options instead of setting REDIS_HOST etc individually Close #1986
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/ostatus.rb | 9 | ||||
-rw-r--r-- | config/initializers/redis.rb | 20 | ||||
-rw-r--r-- | config/initializers/sidekiq.rb | 9 |
3 files changed, 24 insertions, 14 deletions
diff --git a/config/initializers/ostatus.rb b/config/initializers/ostatus.rb index 155d0a9f1..a905a032c 100644 --- a/config/initializers/ostatus.rb +++ b/config/initializers/ostatus.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -port = ENV.fetch('PORT') { 3000 } -host = ENV.fetch('LOCAL_DOMAIN') { "localhost:#{port}" } +port = ENV.fetch('PORT') { 3000 } +host = ENV.fetch('LOCAL_DOMAIN') { "localhost:#{port}" } web_host = ENV.fetch('WEB_DOMAIN') { host } -https = ENV['LOCAL_HTTPS'] == 'true' +https = ENV['LOCAL_HTTPS'] == 'true' Rails.application.configure do config.x.local_domain = host @@ -15,7 +15,6 @@ Rails.application.configure do config.x.streaming_api_base_url = 'http://localhost:4000' if Rails.env.production? - config.action_cable.allowed_request_origins = ["http#{https ? 's' : ''}://#{web_host}"] - config.x.streaming_api_base_url = ENV.fetch('STREAMING_API_BASE_URL') { "http#{https ? 's' : ''}://#{web_host}" } + config.x.streaming_api_base_url = ENV.fetch('STREAMING_API_BASE_URL') { "http#{https ? 's' : ''}://#{web_host}" } end end diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb index 3660c4a9b..dd7fa112e 100644 --- a/config/initializers/redis.rb +++ b/config/initializers/redis.rb @@ -1,8 +1,22 @@ # frozen_string_literal: true +if ENV['REDIS_URL'].blank? + password = ENV.fetch('REDIS_PASSWORD') { '' } + host = ENV.fetch('REDIS_HOST') { 'localhost' } + port = ENV.fetch('REDIS_PORT') { 6379 } + db = ENV.fetch('REDIS_DB') { 0 } + + ENV['REDIS_URL'] = "redis://#{password.blank? ? '' : ":#{password}@"}#{host}:#{port}/#{db}" +end + Redis.current = Redis.new( - host: ENV.fetch('REDIS_HOST') { 'localhost' }, - port: ENV.fetch('REDIS_PORT') { 6379 }, - password: ENV.fetch('REDIS_PASSWORD') { false }, + url: ENV['REDIS_URL'], driver: :hiredis ) + +Rails.application.configure do + config.cache_store = :redis_store, ENV['REDIS_URL'], { + namespace: 'cache', + expires_in: 10.minutes, + } +end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 8ae3bd5a2..3d2e4741d 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,12 +1,9 @@ -host = ENV.fetch('REDIS_HOST') { 'localhost' } -port = ENV.fetch('REDIS_PORT') { 6379 } -password = ENV.fetch('REDIS_PASSWORD') { false } -db = ENV.fetch('REDIS_DB') { 0 } +# frozen_string_literal: true Sidekiq.configure_server do |config| - config.redis = { host: host, port: port, db: db, password: password } + config.redis = { url: ENV['REDIS_URL'] } end Sidekiq.configure_client do |config| - config.redis = { host: host, port: port, db: db, password: password } + config.redis = { url: ENV['REDIS_URL'] } end |