node-karin 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/db/redis.js +5 -5
- package/lib/utils/common.js +6 -2
- package/lib/utils/yamlEditor.d.ts +1 -0
- package/lib/utils/yamlEditor.js +3 -10
- package/package.json +1 -1
package/lib/db/redis.js
CHANGED
|
@@ -18,7 +18,7 @@ class Redis {
|
|
|
18
18
|
/** 集群模式 */
|
|
19
19
|
if (cluster && cluster.enable) {
|
|
20
20
|
const rootNodes = cluster.rootNodes.map((node) => ({ url: node }))
|
|
21
|
-
logger.
|
|
21
|
+
logger.debug('正在连接 Redis 集群...')
|
|
22
22
|
const { status, data } = await this.connectCluster(rootNodes)
|
|
23
23
|
if (status === 'ok') {
|
|
24
24
|
logger.info('Redis 集群连接成功')
|
|
@@ -27,7 +27,7 @@ class Redis {
|
|
|
27
27
|
logger.error(`Redis 集群建立连接失败:${logger.red(data)}`)
|
|
28
28
|
return false
|
|
29
29
|
}
|
|
30
|
-
logger.
|
|
30
|
+
logger.debug(`正在连接 ${logger.green(`Redis://${host}:${port}/${database}`)}`)
|
|
31
31
|
const options = { socket: { host, port }, username, password, database }
|
|
32
32
|
/** 第一次连接 */
|
|
33
33
|
const { status, data } = await this.connect(options)
|
|
@@ -50,10 +50,10 @@ class Redis {
|
|
|
50
50
|
logger.info('Redis 连接成功')
|
|
51
51
|
return data
|
|
52
52
|
}
|
|
53
|
-
logger.
|
|
53
|
+
logger.debug(`Redis 二次建立连接失败:${logger.red(data)}`)
|
|
54
54
|
return false
|
|
55
55
|
} catch (error) {
|
|
56
|
-
logger.
|
|
56
|
+
logger.debug(`Redis 启动失败:${logger.red(data)}`)
|
|
57
57
|
return await this.LevelDB()
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -63,7 +63,7 @@ class Redis {
|
|
|
63
63
|
*/
|
|
64
64
|
async LevelDB () {
|
|
65
65
|
try {
|
|
66
|
-
logger.
|
|
66
|
+
logger.debug('使用LevelDB代替Redis实现基础Api')
|
|
67
67
|
const redis = new RedisLevel()
|
|
68
68
|
return redis
|
|
69
69
|
} catch (error) {
|
package/lib/utils/common.js
CHANGED
|
@@ -568,7 +568,9 @@ class Common {
|
|
|
568
568
|
settings.forEach(({ key, val }) => {
|
|
569
569
|
try {
|
|
570
570
|
if (!yaml.has(key)) { yaml.set(key, val) }
|
|
571
|
-
} catch {
|
|
571
|
+
} catch (error) {
|
|
572
|
+
logger.error(`[common] 更新yaml文件时出错:${error.stack || error.message || error}`)
|
|
573
|
+
}
|
|
572
574
|
})
|
|
573
575
|
/** 先保存 */
|
|
574
576
|
yaml.save()
|
|
@@ -577,7 +579,9 @@ class Common {
|
|
|
577
579
|
settings.forEach(({ key, comment }) => {
|
|
578
580
|
try {
|
|
579
581
|
yaml.comment(key, comment, true)
|
|
580
|
-
} catch {
|
|
582
|
+
} catch (error) {
|
|
583
|
+
logger.error(`[common] 更新yaml文件时出错:${error.stack || error.message || error}`)
|
|
584
|
+
}
|
|
581
585
|
})
|
|
582
586
|
yaml.save()
|
|
583
587
|
}
|
package/lib/utils/yamlEditor.js
CHANGED
|
@@ -270,17 +270,10 @@ export class YamlEditor {
|
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
272
|
* 保存文件
|
|
273
|
+
* 保存失败会抛出异常
|
|
273
274
|
*/
|
|
274
275
|
save () {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
logger.info('[YamlEditor] 文件未更改,无需保存')
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
fs.writeFileSync(this.filePath, this.document.toString())
|
|
281
|
-
logger.info('[YamlEditor] 文件已保存')
|
|
282
|
-
} catch (error) {
|
|
283
|
-
logger.error(`[YamlEditor] 保存文件时出错:${error}`)
|
|
284
|
-
}
|
|
276
|
+
fs.writeFileSync(this.filePath, this.document.toString())
|
|
277
|
+
logger.debug('[YamlEditor] 文件已保存')
|
|
285
278
|
}
|
|
286
279
|
}
|