0
0
Fork 0

Clean up redis configuration. Allow using REDIS_URL to set advanced (#2732)

connection options instead of setting REDIS_HOST etc individually

Close #1986
This commit is contained in:
Eugen Rochko 2017-05-03 23:18:13 +02:00 committed by GitHub
parent 005f1fd360
commit c997091166
8 changed files with 53 additions and 61 deletions

View file

@ -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

View file

@ -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

View file

@ -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