Skip to content

Commit ccb51fb

Browse files
Add RAILS_RESQUE_REDIS_PASSWORD env var support
1 parent 5153bd5 commit ccb51fb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ end
4242

4343
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.
4444

45+
If you need to set a password for your redis server, use this env variable.
46+
```
47+
RAILS_RESQUE_REDIS_PASSWORD=secure_pass
48+
```
49+
4550
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).
4651

4752

config/initializers/resque_config.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
require 'resque'
22

3-
# Previously, this initializer always set Resque.redis, and defaulted to '127.0.0.1:6379' if
4-
# RAILS_RESQUE_REDIS was not set.
5-
3+
# Previously, this initializer always set Resque.redis, and defaulted
4+
# to '127.0.0.1:6379' if RAILS_RESQUE_REDIS was not set.
65
if ENV['RAILS_RESQUE_REDIS'].present?
76
Resque.redis = ENV['RAILS_RESQUE_REDIS']
87
end
8+
9+
# Have to do this to accept password because resque does not support
10+
# setting it in the string.
11+
redis_password = ENV['RAILS_RESQUE_REDIS_PASSWORD']
12+
if redis_password.present?
13+
opts = Resque.redis.client.options
14+
redis = Redis.new(opts.merge(password: redis_password))
15+
Resque.redis = redis
16+
end

0 commit comments

Comments
 (0)