The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
804 B

  1. # frozen_string_literal: true
  2. if ENV['REDIS_URL'].blank?
  3. password = ENV.fetch('REDIS_PASSWORD') { '' }
  4. host = ENV.fetch('REDIS_HOST') { 'localhost' }
  5. port = ENV.fetch('REDIS_PORT') { 6379 }
  6. db = ENV.fetch('REDIS_DB') { 0 }
  7. ENV['REDIS_URL'] = "redis://#{password.blank? ? '' : ":#{password}@"}#{host}:#{port}/#{db}"
  8. end
  9. redis_connection = Redis.new(
  10. url: ENV['REDIS_URL'],
  11. driver: :hiredis
  12. )
  13. cache_params = { expires_in: 10.minutes }
  14. namespace = ENV.fetch('REDIS_NAMESPACE') { nil }
  15. if namespace
  16. Redis.current = Redis::Namespace.new(namespace, :redis => redis_connection)
  17. cache_params[:namespace] = namespace + '_cache'
  18. else
  19. Redis.current = redis_connection
  20. end
  21. Rails.application.configure do
  22. config.cache_store = :redis_store, ENV['REDIS_URL'], cache_params
  23. end