@azteam/redis-async 1.0.90 → 1.0.91
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/RedisAsync.js +35 -39
- package/package.json +2 -2
- package/src/RedisAsync.js +9 -16
package/lib/RedisAsync.js
CHANGED
|
@@ -82,7 +82,7 @@ var RedisAsync = /*#__PURE__*/function () {
|
|
|
82
82
|
this.client = (0, _redis.createClient)({
|
|
83
83
|
host: this.host,
|
|
84
84
|
port: this.port,
|
|
85
|
-
retry_strategy: function retry_strategy(
|
|
85
|
+
retry_strategy: function retry_strategy() {
|
|
86
86
|
_this.connected = false;
|
|
87
87
|
_this._alert('connect', 'Redis disconnected');
|
|
88
88
|
_this.client.quit();
|
|
@@ -115,28 +115,27 @@ var RedisAsync = /*#__PURE__*/function () {
|
|
|
115
115
|
defaultValue = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : null;
|
|
116
116
|
prefixKey = this.parsePrefix(key);
|
|
117
117
|
if (!this.connected) {
|
|
118
|
-
_context2.next =
|
|
118
|
+
_context2.next = 10;
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
_context2.next = 6;
|
|
121
|
+
_context2.next = 5;
|
|
123
122
|
return this.client.get(prefixKey);
|
|
124
|
-
case
|
|
123
|
+
case 5:
|
|
125
124
|
data = _context2.sent;
|
|
126
125
|
if (!data) {
|
|
127
|
-
_context2.next =
|
|
126
|
+
_context2.next = 8;
|
|
128
127
|
break;
|
|
129
128
|
}
|
|
130
129
|
return _context2.abrupt("return", JSON.parse(data));
|
|
131
|
-
case
|
|
132
|
-
_context2.next =
|
|
130
|
+
case 8:
|
|
131
|
+
_context2.next = 12;
|
|
133
132
|
break;
|
|
134
|
-
case
|
|
133
|
+
case 10:
|
|
135
134
|
this.connect();
|
|
136
135
|
return _context2.abrupt("return", null);
|
|
137
|
-
case
|
|
136
|
+
case 12:
|
|
138
137
|
return _context2.abrupt("return", defaultValue);
|
|
139
|
-
case
|
|
138
|
+
case 13:
|
|
140
139
|
case "end":
|
|
141
140
|
return _context2.stop();
|
|
142
141
|
}
|
|
@@ -213,27 +212,26 @@ var RedisAsync = /*#__PURE__*/function () {
|
|
|
213
212
|
count = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : 0;
|
|
214
213
|
prefixKey = this.parsePrefix(key);
|
|
215
214
|
if (!this.connected) {
|
|
216
|
-
_context5.next =
|
|
215
|
+
_context5.next = 9;
|
|
217
216
|
break;
|
|
218
217
|
}
|
|
219
|
-
|
|
220
|
-
_context5.next = 7;
|
|
218
|
+
_context5.next = 6;
|
|
221
219
|
return this.client.set(prefixKey, JSON.stringify(data));
|
|
222
|
-
case
|
|
223
|
-
_context5.next =
|
|
220
|
+
case 6:
|
|
221
|
+
_context5.next = 8;
|
|
224
222
|
return this.expire(prefixKey, timeSecond);
|
|
225
|
-
case
|
|
223
|
+
case 8:
|
|
226
224
|
return _context5.abrupt("return", true);
|
|
227
|
-
case
|
|
225
|
+
case 9:
|
|
228
226
|
this.connect();
|
|
229
227
|
if (!(count < 5)) {
|
|
230
|
-
_context5.next =
|
|
228
|
+
_context5.next = 12;
|
|
231
229
|
break;
|
|
232
230
|
}
|
|
233
231
|
return _context5.abrupt("return", this.set(key, data, timeSecond, count + 1));
|
|
234
|
-
case
|
|
232
|
+
case 12:
|
|
235
233
|
return _context5.abrupt("return", false);
|
|
236
|
-
case
|
|
234
|
+
case 13:
|
|
237
235
|
case "end":
|
|
238
236
|
return _context5.stop();
|
|
239
237
|
}
|
|
@@ -266,46 +264,44 @@ var RedisAsync = /*#__PURE__*/function () {
|
|
|
266
264
|
count = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 0;
|
|
267
265
|
prefixKey = this.parsePrefix(key);
|
|
268
266
|
if (!this.connected) {
|
|
269
|
-
_context6.next =
|
|
267
|
+
_context6.next = 17;
|
|
270
268
|
break;
|
|
271
269
|
}
|
|
272
270
|
if (!exact) {
|
|
273
|
-
_context6.next =
|
|
271
|
+
_context6.next = 9;
|
|
274
272
|
break;
|
|
275
273
|
}
|
|
276
|
-
|
|
277
|
-
_context6.next = 8;
|
|
274
|
+
_context6.next = 7;
|
|
278
275
|
return this.client.del(prefixKey);
|
|
279
|
-
case
|
|
280
|
-
_context6.next =
|
|
276
|
+
case 7:
|
|
277
|
+
_context6.next = 15;
|
|
281
278
|
break;
|
|
282
|
-
case
|
|
279
|
+
case 9:
|
|
283
280
|
regexKey = "*".concat(prefixKey, "*");
|
|
284
|
-
_context6.next =
|
|
281
|
+
_context6.next = 12;
|
|
285
282
|
return this.client.keys(regexKey);
|
|
286
|
-
case
|
|
283
|
+
case 12:
|
|
287
284
|
keys = _context6.sent;
|
|
288
285
|
if (!(keys.length > 0)) {
|
|
289
|
-
_context6.next =
|
|
286
|
+
_context6.next = 15;
|
|
290
287
|
break;
|
|
291
288
|
}
|
|
292
|
-
console.log("Redis REMOVE keys", keys);
|
|
293
289
|
return _context6.abrupt("return", this.client.del(keys));
|
|
294
|
-
case
|
|
295
|
-
_context6.next =
|
|
290
|
+
case 15:
|
|
291
|
+
_context6.next = 21;
|
|
296
292
|
break;
|
|
297
|
-
case
|
|
293
|
+
case 17:
|
|
298
294
|
this.connect();
|
|
299
295
|
if (!(count < 5)) {
|
|
300
|
-
_context6.next =
|
|
296
|
+
_context6.next = 20;
|
|
301
297
|
break;
|
|
302
298
|
}
|
|
303
299
|
return _context6.abrupt("return", this.remove(key, exact, count + 1));
|
|
304
|
-
case
|
|
300
|
+
case 20:
|
|
305
301
|
return _context6.abrupt("return", false);
|
|
306
|
-
case
|
|
302
|
+
case 21:
|
|
307
303
|
return _context6.abrupt("return", false);
|
|
308
|
-
case
|
|
304
|
+
case 22:
|
|
309
305
|
case "end":
|
|
310
306
|
return _context6.stop();
|
|
311
307
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azteam/redis-async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.91",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toda",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"main": "./lib/index.js",
|
|
14
14
|
"module": "./src/index.js",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "babel src
|
|
16
|
+
"build": "babel src --delete-dir-on-start -d lib"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@azteam/util": "1.0.38",
|
package/src/RedisAsync.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {createClient} from 'redis';
|
|
2
|
+
|
|
2
3
|
import {timeout} from '@azteam/util';
|
|
3
4
|
|
|
4
5
|
class RedisAsync {
|
|
@@ -33,7 +34,7 @@ class RedisAsync {
|
|
|
33
34
|
host: this.host,
|
|
34
35
|
port: this.port,
|
|
35
36
|
|
|
36
|
-
retry_strategy: (
|
|
37
|
+
retry_strategy: () => {
|
|
37
38
|
this.connected = false;
|
|
38
39
|
this._alert('connect', 'Redis disconnected');
|
|
39
40
|
this.client.quit();
|
|
@@ -60,8 +61,6 @@ class RedisAsync {
|
|
|
60
61
|
const prefixKey = this.parsePrefix(key);
|
|
61
62
|
|
|
62
63
|
if (this.connected) {
|
|
63
|
-
console.log(`Redis GET ${prefixKey}`);
|
|
64
|
-
|
|
65
64
|
const data = await this.client.get(prefixKey);
|
|
66
65
|
if (data) {
|
|
67
66
|
return JSON.parse(data);
|
|
@@ -88,18 +87,16 @@ class RedisAsync {
|
|
|
88
87
|
const prefixKey = this.parsePrefix(key);
|
|
89
88
|
|
|
90
89
|
if (this.connected) {
|
|
91
|
-
console.log(`Redis SET ${prefixKey}`);
|
|
92
90
|
await this.client.set(prefixKey, JSON.stringify(data));
|
|
93
91
|
await this.expire(prefixKey, timeSecond);
|
|
94
92
|
return true;
|
|
95
|
-
}
|
|
96
|
-
this.connect();
|
|
93
|
+
}
|
|
97
94
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return false;
|
|
95
|
+
this.connect();
|
|
96
|
+
if (count < 5) {
|
|
97
|
+
return this.set(key, data, timeSecond, count + 1);
|
|
102
98
|
}
|
|
99
|
+
return false;
|
|
103
100
|
}
|
|
104
101
|
|
|
105
102
|
// async scan(pattern, cursor = 0, count = 1000) {
|
|
@@ -112,16 +109,12 @@ class RedisAsync {
|
|
|
112
109
|
|
|
113
110
|
if (this.connected) {
|
|
114
111
|
if (exact) {
|
|
115
|
-
console.log(`Redis REMOVE ${prefixKey}`);
|
|
116
|
-
|
|
117
112
|
await this.client.del(prefixKey);
|
|
118
113
|
} else {
|
|
119
|
-
const regexKey = `*${prefixKey}
|
|
120
|
-
|
|
121
|
-
const keys = await this.client.keys(regexKey);
|
|
114
|
+
const regexKey = `*${prefixKey}*`,
|
|
115
|
+
keys = await this.client.keys(regexKey);
|
|
122
116
|
|
|
123
117
|
if (keys.length > 0) {
|
|
124
|
-
console.log(`Redis REMOVE keys`, keys);
|
|
125
118
|
return this.client.del(keys);
|
|
126
119
|
}
|
|
127
120
|
}
|