after_fork and redis

bradford fingermark at
Mon Oct 1 15:31:07 UTC 2012

I'm using unicorn w/ a rails app.  I have the following in my
environment.rb $redis = MyApplication::Application.config.redis and in
production.rb I have config.redis = "localhost").

I've read I'm supposed to $redis = "localhost") in
after_fork when preload_app is true.

When I don't do this, each worker/pid seems to have their own redis
instance.  So, why is this needed?  Here's the logs of me printing out
$redis.client.inspect when both $redis = in the after_fork
and just $redis = in the environment.rb.

No after fork

After fork

The only thing different I notice is Connection::TCPSocket:fd is
always 13 w/ the after fork.

More information about the mongrel-unicorn mailing list