Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Unify redis initialization

REDISTOGO_URL is now deprecated in favor of REDIS_URL which is supported by the redis gem too.
  • Loading branch information...
commit 48dcccf7b3904072e41645a143df75adc3c818a0 1 parent f163108
Jonne Haß jhass authored
22 app/models/app_config.rb
View
@@ -130,7 +130,7 @@ def self.normalize_pod_services
end
end
end
- end
+ ende
def deprecate_hoptoad_api_key
if self[:hoptoad_api_key].present?
@@ -170,4 +170,24 @@ def self.pod_uri
def self.single_process_mode?
(ENV['SINGLE_PROCESS'] == "true" || ENV['SINGLE_PROCESS_MODE'] == "true" || self[:single_process_mode]) ? true : false
end
+
+ def self.get_redis_instance
+ if ENV["REDISTOGO_URL"].present?
+ puts "WARNING: using the REDISTOGO_URL environment variable is deprecated, please use REDIS_URL now."
+ ENV['REDIS_URL'] = ENV["REDISTOGO_URL"]
+ end
+
+ redis_options = {}
+
+ if ENV['REDIS_URL'].present?
+ redis_options = { :url => ENV['REDIS_URL'] }
+ elsif ENV['RAILS_ENV']== 'integration2'
+ redis_options = { :host => 'localhost', :port => 6380 }
+ elsif AppConfig[:redis_url].present?
+ puts "WARNING: You're redis_url doesn't start with redis://" unless AppConfig[:redis_url].start_with?("redis://")
+ redis_options = { :url => AppConfig[:redis_url] }
+ end
+
+ Redis.new(redis_options.merge(:thread_safe => true))
+ end
end
9 config/application.yml.example
View
@@ -24,10 +24,13 @@ defaults: &defaults
## Examples, uncomment one or add your own:
ca_file: '/etc/pki/tls/certs/ca-bundle.crt'
- ## URL for a remote redis, on the default port.
+ ## Redis URL for a remote redis.
## Don't forget to restrict IP access!
- ## Leave it empty for the default (localhost)
- redis_url: ''
+ ## Leave it empty for the default ('redis://localhost:6379/0')
+ ## You can specify a username and password in it, for example
+ ## redis://user:password@remote_host:6379/0
+ ## You can also specify a unix socket URL like unix://tmp/redis.sock
+ redis_url:
## Serve static assets via the appserver.
## This is highly not recommended for production use,
14 config/initializers/resque.rb
View
@@ -3,19 +3,7 @@
Resque::Plugins::Timeout.timeout = 300
if !AppConfig.single_process_mode?
- if redis_to_go = ENV["REDISTOGO_URL"]
- uri = URI.parse(redis_to_go)
- redis_options = { :host => uri.host, :port => uri.port,
- :passsword => uri.password }
- elsif ENV['RAILS_ENV']== 'integration2'
- redis_options = { :host => 'localhost', :port => 6380 }
- elsif AppConfig[:redis_url].present?
- redis_options = { :url => AppConfig[:redis_url], :port => 6379 }
- end
-
- if redis_options
- Resque.redis = Redis.new(redis_options.merge(:thread_safe => true))
- end
+ Resque.redis = AppConfig.get_redis_instance
end
# Single process-mode hooks using Resque.inline
7 config/unicorn.rb
View
@@ -47,12 +47,7 @@
# copy pasta from resque.rb because i'm a bad person
if !AppConfig.single_process_mode?
- if redis_to_go = ENV["REDISTOGO_URL"]
- uri = URI.parse(redis_to_go)
- Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
- elsif AppConfig[:redis_url]
- Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379)
- end
+ Resque.redis = AppConfig.get_redis_instance
end
# Enable this line to have the workers run as different user/group
Please sign in to comment.
Something went wrong with that request. Please try again.