Skip to content

Commit

Permalink
Add RAILS_RESQUE_REDIS_PASSWORD env var support
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillplatonov committed Sep 27, 2017
1 parent 5153bd5 commit ccb51fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ end

If `RAILS_RESQUE_REDIS` is set in `ENV` and is not the empty string, this gem will set `Resque.redis` equal to `ENV['RAILS_RESQUE_REDIS']` in an initializer.

If you need to set a password for your redis server, use this env variable.
```
RAILS_RESQUE_REDIS_PASSWORD=secure_pass
```

For info on configuring Resque itself (and accepted values of `Resque.redis`) see [the Configuration section of the Resque README](https://github.com/resque/resque#configuration).


Expand Down
14 changes: 11 additions & 3 deletions config/initializers/resque_config.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
require 'resque'

# Previously, this initializer always set Resque.redis, and defaulted to '127.0.0.1:6379' if
# RAILS_RESQUE_REDIS was not set.

# Previously, this initializer always set Resque.redis, and defaulted
# to '127.0.0.1:6379' if RAILS_RESQUE_REDIS was not set.
if ENV['RAILS_RESQUE_REDIS'].present?
Resque.redis = ENV['RAILS_RESQUE_REDIS']
end

# Have to do this to accept password because resque does not support
# setting it in the string.
redis_password = ENV['RAILS_RESQUE_REDIS_PASSWORD']
if redis_password.present?
opts = Resque.redis.client.options
redis = Redis.new(opts.merge(password: redis_password))
Resque.redis = redis
end

0 comments on commit ccb51fb

Please sign in to comment.