栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Redis Gem(Ruby)救援超时::错误

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Redis Gem(Ruby)救援超时::错误

您在irb中运行了此代码,对吗?您收到的异常实际上不是由引发的

Redis.new
。它是由
inspect
方法引发的,irb调用该方法以向您显示刚刚键入的表达式的值。

只需查看堆栈跟踪(我缩短了使其清晰的路径):

ruby-1.8.7-p330 :009 >   Redis.new(:host => "google.com")Timeout::Error: time's up!    from /.../SystemTimer-1.2.3/lib/system_timer/concurrent_timer_pool.rb:63:in `trigger_next_expired_timer_at'    from /.../SystemTimer-1.2.3/lib/system_timer/concurrent_timer_pool.rb:68:in `trigger_next_expired_timer'    from /.../SystemTimer-1.2.3/lib/system_timer.rb:85:in `install_ruby_sigalrm_handler'    from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'    from /.../SystemTimer-1.2.3/lib/system_timer.rb:83:in `install_ruby_sigalrm_handler'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `call'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `initialize'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `new'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:26:in `connect'    from /.../SystemTimer-1.2.3/lib/system_timer.rb:60:in `timeout_after'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:115:in `with_timeout'    from /.../redis-2.2.2/lib/redis/connection/ruby.rb:25:in `connect'    from /.../redis-2.2.2/lib/redis/client.rb:227:in `establish_connection'    from /.../redis-2.2.2/lib/redis/client.rb:23:in `connect'    from /.../redis-2.2.2/lib/redis/client.rb:247:in `ensure_connected'    from /.../redis-2.2.2/lib/redis/client.rb:137:in `process'... 2 levels...    from /.../redis-2.2.2/lib/redis/client.rb:46:in `call'    from /.../redis-2.2.2/lib/redis.rb:90:in `info'    from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'    from /.../redis-2.2.2/lib/redis.rb:89:in `info'    from /.../redis-2.2.2/lib/redis.rb:1075:in `inspect'    from /..../lib/ruby/1.8/monitor.rb:242:in `synchronize'    from /.../redis-2.2.2/lib/redis.rb:1074:in `inspect'    from /..../lib/ruby/1.8/irb.rb:310:in `output_value'    from /..../lib/ruby/1.8/irb.rb:159:in `eval_input'    from /..../lib/ruby/1.8/irb.rb:271:in `signal_status'    from /..../lib/ruby/1.8/irb.rb:155:in `eval_input'    from /..../lib/ruby/1.8/irb.rb:154:in `eval_input'    from /..../lib/ruby/1.8/irb.rb:71:in `start'    from /..../lib/ruby/1.8/irb.rb:70:in `catch'    from /..../lib/ruby/1.8/irb.rb:70:in `start'    from /..../bin/irb:17

如您在上面看到的,该异常发生在

inspect
而不是内部
Redis.new
。当您调用
inspect
Redis对象时,它实际上不仅仅是在打印其状态,而且还可以做很多事情。在这种情况下,
inspect
尝试连接到服务器并在超时时引发异常。这对我来说似乎是一个非常糟糕的设计,也许我们应该向Redis
gem的维护者提交错误报告。

这导致了IRB中一些有趣的行为:

  • 键入会
    Redis.new(:host => "google.com")
    导致异常,如上所示
  • 输入
    Redis.new(:host => "google.com"); 'hello'
    结果为’
    => "hello"

如果要捕获此异常,请尝试

ensure_connected
在begin / rescue / end块内调用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/399468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号