After upgrade redis to 2.6.12, the problem resolved.
Spork rspec while using redis, raise Redis::InheritedError
Question
If the code excute redis related function, it will raise
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
when redis connect it will save the spork process.pid as @pid, then redis excute it will check the connect using ensure_connected
, which will check by Process.pid != @pid
. and these two pids are different, so it raise Redis::InheritedError.
By Google it,
Resque.after_fork do
Resque.redis.client.reconnect
end
and reconnect the redis client every spec
Both of them don't work for me.
Solution 2
OTHER TIPS
I found the solution here, and it worked for me: Hacki.ly
Looks like it's a matter of adding the following in your spec_helper.rb:
RSpec.configure do |config|
# ...
config.before :all do
$redis.client.reconnect
end
# ...
end
You may need to change $redis
to whatever you're using to grab a reference to your Redis instance.
I was able to fix this by adding the following to spec_helper.rb:
Spork.each_run do
$redis.client.reconnect
end
Also as mentioned in Gabe's answer, you may need to change $redis
to whatever you're using to grab a reference to your Redis instance.