鉴于以下node.js
+ oriento
示例代码,我遇到超时问题,[OrientDB.ConnectionError [2]: read ETIMEDOUT]
,在一段较长的不活动期后我第一次进行数据库查询。在超时错误之后,连接会以某种方式重新初始化,并且下一个查询运行正常。
var oriento = require("oriento"),
server = oriento({...}),
db = server.use("users");
var getData = function(statement, opts, callback) {
db.query(statement, opts).then(function(data) {
callback(null, data);
}).catch(callback);
};
所以我有以下问题:
- 这是正确的方法还是我应该打电话
oriento({...}).use("users")
每次我进行查询而不是重用连接对象时? - 如果这是正确的方法,为什么连接不会自动验证和刷新?
- 如何手动检查是否会遇到超时(即验证连接)并强制刷新连接?
最佳答案
有什么建议比下面这个相当丑陋的黑客通过每分钟 ping 数据库来保持传输套接字更好吗?
setInterval(function(db) {
db.query("select from user").then(function(data) {
console.log("still alive");
}).catch(function(err) {
console.error(err);
});
}, 60000, db);
关于node.js - 避免 oriento 中的查询超时(OrientDB 的 Node.js 驱动程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29257860/