mm_redis 1.9.1 → 1.9.2
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/index.js +13 -19
- package/package.json +1 -1
- package/test.js +1 -2
package/index.js
CHANGED
|
@@ -17,24 +17,13 @@ class Redis extends eventEmitter {
|
|
|
17
17
|
/**
|
|
18
18
|
* @description 创建Redis帮助类函数 (构造函数)
|
|
19
19
|
* @param {String} scope 作用域
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {Object} config 配置参数
|
|
21
21
|
* @constructor
|
|
22
22
|
*/
|
|
23
|
-
constructor(scope,
|
|
23
|
+
constructor(scope, config) {
|
|
24
24
|
super();
|
|
25
25
|
// 作用域
|
|
26
|
-
this.scope;
|
|
27
|
-
if (scope) {
|
|
28
|
-
this.scope = scope;
|
|
29
|
-
} else {
|
|
30
|
-
this.scope = $.val.scope + '';
|
|
31
|
-
}
|
|
32
|
-
// 当前目录
|
|
33
|
-
this.dir = __dirname;
|
|
34
|
-
if (dir) {
|
|
35
|
-
this.dir = dir;
|
|
36
|
-
}
|
|
37
|
-
|
|
26
|
+
this.scope = scope;
|
|
38
27
|
// 配置参数
|
|
39
28
|
this.config = {
|
|
40
29
|
// 服务器地址
|
|
@@ -54,6 +43,7 @@ class Redis extends eventEmitter {
|
|
|
54
43
|
// 重试间隔(ms)
|
|
55
44
|
"retry_delay": 1000
|
|
56
45
|
};
|
|
46
|
+
this.setConfig(config);
|
|
57
47
|
// 连接池配置
|
|
58
48
|
this.connectionPool = {
|
|
59
49
|
available: [], // 可用连接数组
|
|
@@ -183,8 +173,12 @@ Redis.prototype.setConfig = function (cg) {
|
|
|
183
173
|
let obj = {};
|
|
184
174
|
if (typeof cg === 'string') {
|
|
185
175
|
obj = cg.loadJson(__dirname);
|
|
186
|
-
} else {
|
|
187
|
-
|
|
176
|
+
} else if (cg) {
|
|
177
|
+
// 合并配置参数
|
|
178
|
+
Object.assign(this.config, cg);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return;
|
|
188
182
|
}
|
|
189
183
|
// 使用Object.assign替代$.push来合并配置
|
|
190
184
|
this.config = Object.assign({}, this.config || {}, obj);
|
|
@@ -2926,16 +2920,16 @@ if (!$.pool.redis) {
|
|
|
2926
2920
|
/**
|
|
2927
2921
|
* @description Redis管理器,用于创建缓存
|
|
2928
2922
|
* @param {String} scope 作用域
|
|
2929
|
-
* @param {
|
|
2923
|
+
* @param {Object} config 配置参数
|
|
2930
2924
|
* @return {Object} 返回一个Redis类实例
|
|
2931
2925
|
*/
|
|
2932
|
-
function redis_admin(scope,
|
|
2926
|
+
function redis_admin(scope, config) {
|
|
2933
2927
|
if (!scope) {
|
|
2934
2928
|
scope = 'sys';
|
|
2935
2929
|
}
|
|
2936
2930
|
var obj = $.pool.redis[scope];
|
|
2937
2931
|
if (!obj) {
|
|
2938
|
-
$.pool.redis[scope] = new Redis(scope,
|
|
2932
|
+
$.pool.redis[scope] = new Redis(scope, config);
|
|
2939
2933
|
obj = $.pool.redis[scope];
|
|
2940
2934
|
}
|
|
2941
2935
|
return obj;
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -3,9 +3,8 @@ const { redis_admin } = require('./index.js');
|
|
|
3
3
|
async function test() {
|
|
4
4
|
try {
|
|
5
5
|
var bl, num, arr = [];
|
|
6
|
-
var rs = redis_admin('sys');
|
|
7
6
|
var config = './config.json'.loadJson(__dirname);
|
|
8
|
-
rs
|
|
7
|
+
var rs = redis_admin('sys', config);
|
|
9
8
|
await rs.open();
|
|
10
9
|
|
|
11
10
|
// 测试基本的set和get操作
|