sorentwo / readthis

:newspaper: Pooled active support compliant caching with redis
MIT License
506 stars 40 forks source link

Reconnect on unicorn USR2 #10

Closed jdowning closed 9 years ago

jdowning commented 9 years ago

When restarting unicorn with the USR2 signal, a new master is created and workers are forked off. In my config/unicorn.rb, before switching to readthis, I had Rails.cache.reconnect to reconnect to redis after forking. I believe this was an implementation of the redis-store gem, which you aren't using here.

How would you suggest I reconnect the unicorn worker to the redis-based cache with readthis? Thanks!

sorentwo commented 9 years ago

@justindowning: You don't need to force redis to reconnect, it will automatically reconnect when it encounters inheritance errors. There is a test for this exact use case in the redis-rb repository: fork_safety_test.rb

readthis uses connection_pool to manage multiple connections. While it would be technically possible to iterate over each connection in the pool and force a reconnect, it isn't necessary. In fact, the connection pool documentation even mandates that connections be self repairing!

There is no provision for repairing or checking the health of a connection; connections should be self-repairing. This is true of the Dalli and Redis clients.

So, good news all around. You don't need to do anything!

jdowning commented 9 years ago

Great to hear! Thanks for the quick and thorough response! :green_heart: