我将 Redis 与我的 Rails 应用程序一起使用。我也安装了sidekiq gem。我的 redis 服务器在默认端口的同一台机器上运行。
我创建了一个初始化 redis lient 的初始化程序。
配置/初始化程序/redis.rb
$redis = Redis.new(:host => 'localhost', :port => 6379)
我有另一个初始化程序,用于设置系统中当前活动的帐户数量。
配置/初始化程序/z_account_list.rb
$redis.set('accounts',Account.count);
在我的一个观点中,我正在使用这段代码。
<div class="more-text">and <%= "#{$redis.get('accounts')}" %> more...</div>
当我在 redis 中手动设置帐户值而不使用初始化程序时,一切正常。但是当我添加初始化程序时,我得到
ActionView::Template::Error (Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.):
我搜索了错误。但大多数解决方案都是针对 resque 的,并且与 after_fork 有关。因为我是 Rails 和 Redis 的新手,而且我没有使用 Resque,所以我有点困惑。请帮我解决这个问题。