Redis and ResqueΒΆ

Solano CI sets up an isolated Redis instance for each parallel test worker. The tddium:redis_hook is run once for each redis instance. Note that the soulmate gem does not support the same set of configuration syntaxes as Resque; in particular it does not support the host:port:db syntax so you may need to translate the configuration to redis://host:port/db in your configuration and initialization code.

The Redis configuration is written to config/redis.yml:

# config/redis.yml
---
test: &test
  :host: <%= ENV['TDDIUM_REDIS_HOST'] %>
  :port: <%= ENV['TDDIUM_REDIS_PORT'] %>
  :db: <%= ENV['TDDIUM_REDIS_DB'] %>
  :password: <%= ENV['TDDIUM_REDIS_PASSWORD'] %>
  :timeout: 10

If your redis initializer doesn’t process config/redis.yml with ERB, or it configures using a different model (e.g., if you use a service like RedisToGo with Heroku), you’ll need to update it. For example:

# config/initializers/redis.rb
if ENV['TDDIUM']
  redis = YAML.load(ERB.new(File.read('config/redis.yml')).result)[Rails.env]
  REDIS = Redis.new(redis)
else
  uri = URI.parse(ENV['REDISTOGO_URL'] || 'redis://127.0.0.1')
  REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end

If you only use Redis for Resque, Solano CI also writes config/resque.yml in the format that Resque expects. It still needs to be ERB interpolated:

# config/resque.yml
:test: <%= ENV['TDDIUM_REDIS_HOST'] %>:<%= ENV['TDDIUM_REDIS_PORT'] %>:<%= ENV['TDDIUM_REDIS_DB'] %>

Here’s an example resque initializer:

# config/initalizers/resque.rb
resque_config = YAML.load(ERB.new(File.read(Rails.root.join('config','resque.yml'))).result)
Resque.redis = resque_config[Rails.env]