diff --git a/History.md b/History.md index d0e1556..88495a7 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +2.2.0 / 2018-03-15 +================== + * 连接池增加失败移除配置和恢复时间 + + 2.1.3 / 2018-03-14 ================== * 优化异常输出 diff --git a/index.js b/index.js index fe27909..fce04eb 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,10 @@ class Mysqli { //是否有从库 this.useSlaveDB = config.length > 1 - this.pool = mysql.createPoolCluster() + this.pool = mysql.createPoolCluster({ + removeNodeErrorCount: 1, // 连续失败立即从节点中移除, 并在10秒后尝试恢复 + restoreNodeTimeout: 10000 + }) config.forEach((item, i) => { let { host, port, user, charset, passwd: password, db: database } = item diff --git a/lib/method.js b/lib/method.js index 2bcfc10..5b5ec7e 100644 --- a/lib/method.js +++ b/lib/method.js @@ -23,23 +23,23 @@ class Method { } connect() { - this.defer = Promise.defer() + const defer = Promise.defer() this.pool.getConnection(this.slave, (err, conn) => { if (err) { - return this.defer.reject(new SqlErr(`MySQL connect ${err}`)) + return defer.reject(new SqlErr(`MySQL connect ${err}`)) } if (this.db) { conn.query('USE ' + this.db, err => { if (err) { - return this.defer.reject(new SqlErr('Select DB ' + err)) + return defer.reject(new SqlErr('Select DB ' + err)) } - this.defer.resolve(conn) + defer.resolve(conn) }) } else { - this.defer.resolve(conn) + defer.resolve(conn) } }) - return this.defer.promise + return defer.promise } listDb() { diff --git a/package.json b/package.json index 6891276..32216ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mysqli", - "version": "2.1.3", + "version": "2.2.0", "description": "MySQL tool", "main": "index.js", "dependencies": {