当通过 Ruby 连接到 Mongo 时,我们需要设置一个超时值。我们在 Mongo 2.2 上。
我们应该使用:timeout
or:connect_timeout
吗?我们在 SO 和其他地方看到使用这两个选项的代码片段。有什么区别?
您可以在此处查看不同的超时时间:
https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/mongo_client.rb#L104
从那里复制:
# @option opts [Float] :timeout (5.0) When all of the self.connections a pool are checked out, # this is the number of seconds to wait for a new connection to be released before throwing an exception. # Note: this setting is relevant only for multi-threaded applications. # @option opts [Float] :op_timeout (nil) The number of seconds to wait for a read operation to time out. # Disabled by default. # @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a # connection attempt.