如何为mysql设置ActiveRecord查询超时?

esi*_*ver 5 mysql activerecord timeout

如何在ActiveRecord中设置mysql查询超时?我希望把它设置得很短,比如10-15ms.这是一个Sinatra红宝石网络应用程序.

谢谢.

esi*_*ver 7

好吧,看来mysql_adapter.rb中的这些第29行和第30行,

  @connection.options(Mysql::OPT_READ_TIMEOUT, @config[:read_timeout]) if @config[:read_timeout]
  @connection.options(Mysql::OPT_WRITE_TIMEOUT, @config[:write_timeout]) if @config[:write_timeout]
Run Code Online (Sandbox Code Playgroud)

只需要将read_timeout和write_timeout值添加到.yaml数据库配置文件中.

从而,

development:
  adapter: mysql
  encoding: utf8
  database: app_development
  pool: 5
  username: root
  password: 
  write_timeout: 1
  read_timeout: 1
Run Code Online (Sandbox Code Playgroud)

应该诀窍设置每秒1秒的读写超时.不幸的是,这不允许您设置亚秒级超时.