Clean up redis configuration. Allow using REDIS_URL to set advanced (#2732)
connection options instead of setting REDIS_HOST etc individually Close #1986master
parent
005f1fd360
commit
c997091166
@ -1,10 +0,0 @@ |
||||
development: |
||||
adapter: redis |
||||
url: redis://localhost:6379/1 |
||||
|
||||
test: |
||||
adapter: async |
||||
|
||||
production: |
||||
adapter: redis |
||||
url: redis://<%= ENV['REDIS_PASSWORD'] ? ':' + ENV['REDIS_PASSWORD'] + '@' : '' %><%= ENV['REDIS_HOST'] || 'localhost' %>:<%= ENV['REDIS_PORT'] || 6379 %>/1 |
@ -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 |
||||
|
@ -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 |
||||
|
Loading…
Reference in new issue