I am using redis as a read cache. I have created an initializer
config/initializer/redis.rb
$redis = Redis.new(:host => ENV[\"REDIS_HOST\"], :port =&
try this out:-
you can use constant
instead of global variable
.like in
config/initializer/redis.rb
REDIS = Redis.new(:host => ENV["REDIS_HOST"], :port => ENV["REDIS_PORT"])
and in unicorn.rb
before_fork do |server, worker|
# clear redis connection
REDIS.quit if defined?(REDIS)
end
# Give each child process its own Redis connection
after_fork do |server, worker|
REDIS ||= Redis.new(:host => ENV["REDIS_HOST"], :port => ENV["REDIS_PORT"])
end