我在我的项目中使用redis,并使用redis = Redis.new和redis gem进行初始化。问题是,如果Redis没有运行,我就不能做任何简单的数据库迁移。
有没有一种更优雅的方式来处理使用redis,这样我的应用程序就会抛出一个错误,而不是在redis不运行的时候不工作?
我正在使用进程监控来保持redis正常运行,并监控它的内存/cpu,但如果它不运行,所有的东西都会崩溃,并寻找一种更优雅的方式。如果可能的话
EDit:
这是我的初始化器
$redis = Redis.new
heartbeat_thread = Thread.new do
while true
$redis.publish("heartbeat","thump")
sleep 30.seconds
end
end
at_exit do
# not sure this is needed, but just in case
heartbeat_thread.kill
$redis.quit
end发布于 2013-11-20 04:47:11
为什么在做任何请求之前都要创建到redis的连接?
看起来你并不需要这样做,我建议你只在你需要发送一些请求的时候才连接到redis。
我对redis ruby客户端不是很熟悉,但我相信你可以很容易地做到这一点。
https://stackoverflow.com/questions/20065965
复制相似问题