When deploying redis-store on Rails 2 with unicorn and preload_app in your unicorn config is true, the workers will share an outgoing socket to Redis, causing much pain.
The way around it is to get a new connection after the child has forked in the unicorn conf's after_fork hook, but right now I have to access the Redis object itself to do it:
Am I just missing something? I'm not sure of any other way to do this currently, but I think there should be.
For distributed stores, the method is a little different:
Rails.cache.instance_variable_get(:@data).instance_variable_get(:@ring).instance_variable_get(:@nodes).each do |node|
Introducing Rails.cache.reconnect, useful for Unicorn environments. Closed by 3f0dcb3
Now you can use Rails.cache.reconnect.
Introducing Rails.cache.reconnect, useful for Unicorn environments. C…
Is Rails.cache.reconnect still the correct way to reconnect using Unicorn? I'm having an issue where the cache is trying to use localhost instead of the redistogo settings from the config. But adding the reconnect call didn't fix my issue.
after_fork do |server, worker|
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
Rails.logger.info("Connected to Redis")
Update: Because the connection keeps failing I'm actually ending up in an infinite crash cycle
@adamgotterer that Rails.cache.reconnect calls the Redis adapter for AS (redis-activesupport gem), which delegates to RS core (redis-store gem), which uses Redis client's (redis-rb gem) #reconnect https://github.com/redis-store/redis-store/blob/master/lib/redis/store.rb#L15.
Which version of the Redis gem are you using? Would you please try with a standalone connection and @redis.reconnect in the same environment and circumstance (after_fork)? Before to debug this, I want to be sure the problem belongs to RS. Thanks.
Everything is working now. The problem wasn't with the reconnect. I'm not positive but I think the problems stemmed from calling redis.quit. Thanks.