about summary refs log tree commit diff
path: root/config/initializers/redis.rb
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers/redis.rb')
-rw-r--r--config/initializers/redis.rb20
1 files changed, 17 insertions, 3 deletions
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