0

我刚开始使用 Sequel ruby​​gem,似乎“断开连接”方法不起作用。这是我的 IRB 测试会话的输出:

1.9.3-p194 :002 > require 'sequel'
 => true 
1.9.3-p194 :003 > DB = Sequel.connect('postgres://postgres:mypassword@my_pg_host:5432/my_db')
 => #<Sequel::Postgres::Database: "postgres://postgres:mypassword@my_pg_host:5432/my_db"> 
1.9.3-p194 :004 > DB.test_connection
 => true 
1.9.3-p194 :005 > DB.disconnect
 => [] 
1.9.3-p194 :006 > DB.test_connection
 => true

我在 Sequel 文档中看不到任何说明为什么这不起作用的内容:

http://sequel.rubyforge.org/rdoc/classes/Sequel/Database.html#method-i-disconnect

我错过了什么吗?

4

1 回答 1

1

DB.disconnect断开当前连接池中的所有连接,并从池中删除连接。之后调用DB.test_connection将在连接池中查找连接,并且由于池为空,将导致创建新连接。

您发布的代码完全是预期的行为,但我猜您不知道这DB并不代表与数据库的单个连接。

于 2012-10-19T15:13:53.800 回答