2年間運用しているRailsアプリケーションにRspec高速化のためにspring-commands-rspec
gemを追加したところ発生。
- エラーメッセージ
Redis::InheritedError:
Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking or set :inherit_socket to true.
エラーメッセージを見ると、Springがフォークしてできたプロセスが、Redisとのコネクションが取れていないということらしい。Springのドキュメントを見てみると、フォークした後タイミングのコールバックが用意されていたので利用。
config/spring.rb
Spring.after_fork do
begin
Redis.current = Redis.new(hogehoge)
Redis.current.ping # 接続チェック
rescue => err
Rails.logger.info(err)
end
end
上記エラーが発生した環境はそれぞれだと思いますが、参考になれば幸いです。