|
|
|
@ -1,17 +1,36 @@
|
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
|
|
def setup_redis_env_url(prefix = nil, defaults = true)
|
|
|
|
|
prefix = prefix.to_s.upcase + '_' unless prefix.nil?
|
|
|
|
|
prefix = "#{prefix.to_s.upcase}_" unless prefix.nil?
|
|
|
|
|
prefix = '' if prefix.nil?
|
|
|
|
|
redis_url_key = "#{prefix}REDIS_URL"
|
|
|
|
|
|
|
|
|
|
if ENV[redis_url_key].present?
|
|
|
|
|
conn = +ENV["#{prefix}REDIS_URL"].sub(/redis:\/\//i, '')
|
|
|
|
|
|
|
|
|
|
# Strip any prefixing `unix://`
|
|
|
|
|
unix = !conn.sub!(/^unix:\/\//i, '').nil?
|
|
|
|
|
# Strip any prefixing `./`
|
|
|
|
|
unix |= conn.sub!(/^(\.\/)+/, '')
|
|
|
|
|
unix |= conn.start_with?('/')
|
|
|
|
|
|
|
|
|
|
return if ENV[prefix + 'REDIS_URL'].present?
|
|
|
|
|
if unix
|
|
|
|
|
pn = Pathname.new(conn)
|
|
|
|
|
pn = Pathname.getwd / pn if pn.relative?
|
|
|
|
|
ENV[redis_url_key] = "unix://#{pn}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults }
|
|
|
|
|
host = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults }
|
|
|
|
|
port = ENV.fetch(prefix + 'REDIS_PORT') { 6379 if defaults }
|
|
|
|
|
db = ENV.fetch(prefix + 'REDIS_DB') { 0 if defaults }
|
|
|
|
|
password = ENV.fetch("#{prefix}REDIS_PASSWORD") { '' if defaults }
|
|
|
|
|
host = ENV.fetch("#{prefix}REDIS_HOST") { 'localhost' if defaults }
|
|
|
|
|
port = ENV.fetch("#{prefix}REDIS_PORT") { 6379 if defaults }
|
|
|
|
|
db = ENV.fetch("#{prefix}REDIS_DB") { 0 if defaults }
|
|
|
|
|
|
|
|
|
|
ENV[prefix + 'REDIS_URL'] = begin
|
|
|
|
|
ENV["#{prefix}REDIS_URL"] = begin
|
|
|
|
|
if [password, host, port, db].all?(&:nil?)
|
|
|
|
|
ENV['REDIS_URL']
|
|
|
|
|
else
|
|
|
|
@ -27,7 +46,7 @@ setup_redis_env_url(:cache, false)
|
|
|
|
|
setup_redis_env_url(:sidekiq, false)
|
|
|
|
|
|
|
|
|
|
namespace = ENV.fetch('REDIS_NAMESPACE', nil)
|
|
|
|
|
cache_namespace = namespace ? namespace + '_cache' : 'cache'
|
|
|
|
|
cache_namespace = namespace ? "#{namespace}_cache" : 'cache'
|
|
|
|
|
sidekiq_namespace = namespace
|
|
|
|
|
|
|
|
|
|
REDIS_CACHE_PARAMS = {
|
|
|
|
|