Ruby CONSTANTS are a good way to create small data stores in your classes. In the this example lets look at a way to configure a Redis instance based on our Rails.env variable.

module RedisLoader 
  DATABASES = {
    "development" => 0, 
    "test" => 1, 
    "production" => 2 
  }
 
  def self.store
    @store ||= Redis.new(db: DATABASES[Rails.env.to_s])
  end
end

:)

Leave a Reply

Your email address will not be published. Required fields are marked *