@tiledesk/tiledesk-tybot-connector 0.2.135 → 0.2.136
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/CHANGELOG.md +3 -0
- package/TdCache.js +190 -56
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,9 @@ available on:
|
|
|
17
17
|
- Added flowError on JSONCondition when result = null
|
|
18
18
|
- Added fix on Filler -->
|
|
19
19
|
|
|
20
|
+
# v0.2.136
|
|
21
|
+
- TdCache rollback
|
|
22
|
+
|
|
20
23
|
# v0.2.135
|
|
21
24
|
- Updated to redis 4.7.0 + Tdcache.js
|
|
22
25
|
- Disabled close_directive_test.js - DirClose directive - too old, not passing
|
package/TdCache.js
CHANGED
|
@@ -7,7 +7,6 @@ class TdCache {
|
|
|
7
7
|
this.redis_port = config.port;
|
|
8
8
|
this.redis_password = config.password;
|
|
9
9
|
this.client = null;
|
|
10
|
-
this.redis_sub = null;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
async connect(callback) {
|
|
@@ -25,22 +24,17 @@ class TdCache {
|
|
|
25
24
|
callback(err);
|
|
26
25
|
}
|
|
27
26
|
});
|
|
27
|
+
// this.client.on('connect', function() {
|
|
28
|
+
// console.log('Redis Connected!');
|
|
29
|
+
// });
|
|
28
30
|
this.client.on('ready',function() {
|
|
31
|
+
// console.log("connected")
|
|
29
32
|
resolve();
|
|
30
33
|
if (callback) {
|
|
31
34
|
callback();
|
|
32
35
|
}
|
|
33
36
|
//console.log("Redis is ready.");
|
|
34
37
|
});
|
|
35
|
-
await this.client.connect();
|
|
36
|
-
this.redis_sub = redis.createClient(
|
|
37
|
-
{
|
|
38
|
-
host: this.redis_host,
|
|
39
|
-
port: this.redis_port,
|
|
40
|
-
password: this.redis_password
|
|
41
|
-
});
|
|
42
|
-
// console.log("redis is:", this.redis_sub)
|
|
43
|
-
await this.redis_sub.connect();
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
|
|
@@ -49,59 +43,202 @@ class TdCache {
|
|
|
49
43
|
if (!options) {
|
|
50
44
|
options = {EX: 86400}
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
return new Promise( async (resolve, reject) => {
|
|
47
|
+
if (options && options.EX) {
|
|
48
|
+
//console.log("expires:", options.EX)
|
|
49
|
+
try {
|
|
50
|
+
this.client.set(
|
|
51
|
+
key,
|
|
52
|
+
value,
|
|
53
|
+
'EX', options.EX,
|
|
54
|
+
(err) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
reject(err);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return resolve();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
catch(error) {
|
|
65
|
+
reject(error)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
try {
|
|
70
|
+
//console.log("setting here...key", key, value)
|
|
71
|
+
await this.client.set(
|
|
72
|
+
key,
|
|
73
|
+
value,
|
|
74
|
+
(err) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return resolve();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
catch(error) {
|
|
85
|
+
console.error("TdCache Error:", error);
|
|
86
|
+
reject(error)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// if (options && options.callback) {
|
|
90
|
+
// options.callback();
|
|
91
|
+
// }
|
|
92
|
+
//console.log("resolving...", key);
|
|
93
|
+
// return resolve();
|
|
94
|
+
});
|
|
56
95
|
}
|
|
57
96
|
|
|
58
97
|
async incr(key) {
|
|
59
|
-
|
|
98
|
+
// console.log("incr key:", key)
|
|
99
|
+
return new Promise( async (resolve, reject) => {
|
|
100
|
+
try {
|
|
101
|
+
// console.log("incr here...key", key)
|
|
102
|
+
await this.client.incr(key);
|
|
103
|
+
}
|
|
104
|
+
catch(error) {
|
|
105
|
+
console.error("Error on incr:", error);
|
|
106
|
+
reject(error)
|
|
107
|
+
}
|
|
108
|
+
return resolve();
|
|
109
|
+
});
|
|
60
110
|
}
|
|
61
111
|
|
|
62
112
|
async hset(dict_key, key, value, options) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
113
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
114
|
+
return new Promise( async (resolve, reject) => {
|
|
115
|
+
if (options && options.EX) {
|
|
116
|
+
//console.log("expires:", options.EX)
|
|
117
|
+
try {
|
|
118
|
+
await this.client.hset(
|
|
119
|
+
dict_key,
|
|
120
|
+
key,
|
|
121
|
+
value,
|
|
122
|
+
'EX', options.EX);
|
|
123
|
+
}
|
|
124
|
+
catch(error) {
|
|
125
|
+
reject(error)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
try {
|
|
130
|
+
//console.log("setting here...key", key, value)
|
|
131
|
+
await this.client.hset(
|
|
132
|
+
dict_key,
|
|
133
|
+
key,
|
|
134
|
+
value);
|
|
135
|
+
}
|
|
136
|
+
catch(error) {
|
|
137
|
+
console.error("Error", error);
|
|
138
|
+
reject(error)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (options && options.callback) {
|
|
142
|
+
options.callback();
|
|
143
|
+
}
|
|
144
|
+
return resolve();
|
|
145
|
+
});
|
|
74
146
|
}
|
|
75
147
|
|
|
76
|
-
async hdel(dict_key, key) {
|
|
77
|
-
|
|
148
|
+
async hdel(dict_key, key, options) {
|
|
149
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
150
|
+
return new Promise( async (resolve, reject) => {
|
|
151
|
+
if (options && options.EX) {
|
|
152
|
+
//console.log("expires:", options.EX)
|
|
153
|
+
try {
|
|
154
|
+
await this.client.hdel(
|
|
155
|
+
dict_key,
|
|
156
|
+
key,
|
|
157
|
+
'EX', options.EX);
|
|
158
|
+
}
|
|
159
|
+
catch(error) {
|
|
160
|
+
reject(error)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
try {
|
|
165
|
+
//console.log("setting here...key", key, value)
|
|
166
|
+
await this.client.hdel(
|
|
167
|
+
dict_key,
|
|
168
|
+
key);
|
|
169
|
+
}
|
|
170
|
+
catch(error) {
|
|
171
|
+
console.error("Error", error);
|
|
172
|
+
reject(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (options && options.callback) {
|
|
176
|
+
options.callback();
|
|
177
|
+
}
|
|
178
|
+
return resolve();
|
|
179
|
+
});
|
|
78
180
|
}
|
|
79
181
|
|
|
80
182
|
async setJSON(key, value, options) {
|
|
81
|
-
if (!value) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (!options) {
|
|
85
|
-
options = {EX: 86400}
|
|
86
|
-
}
|
|
87
183
|
const _string = JSON.stringify(value);
|
|
88
184
|
return await this.set(key, _string, options);
|
|
89
185
|
}
|
|
90
186
|
|
|
91
|
-
async get(key) {
|
|
92
|
-
|
|
93
|
-
return
|
|
187
|
+
async get(key, callback) {
|
|
188
|
+
//console.log("getting key", key)
|
|
189
|
+
return new Promise( async (resolve, reject) => {
|
|
190
|
+
this.client.get(key, (err, value) => {
|
|
191
|
+
if (err) {
|
|
192
|
+
reject(err);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (callback) {
|
|
196
|
+
callback(value);
|
|
197
|
+
}
|
|
198
|
+
return resolve(value);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
94
202
|
}
|
|
95
203
|
|
|
96
|
-
async hgetall(dict_key) {
|
|
97
|
-
|
|
98
|
-
return
|
|
204
|
+
async hgetall(dict_key, callback) {
|
|
205
|
+
//console.log("hgetting dics", dict_key);
|
|
206
|
+
return new Promise( async (resolve, reject) => {
|
|
207
|
+
this.client.hgetall(dict_key, (err, value) => {
|
|
208
|
+
if (err) {
|
|
209
|
+
reject(err);
|
|
210
|
+
if (callback) {
|
|
211
|
+
callback(err, null);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (callback) {
|
|
216
|
+
callback(null, value);
|
|
217
|
+
}
|
|
218
|
+
resolve(value);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
99
222
|
}
|
|
100
223
|
|
|
101
|
-
async hget(dict_key, key) {
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
224
|
+
async hget(dict_key, key, callback) {
|
|
225
|
+
//console.log("hgetting dics", dict_key);
|
|
226
|
+
return new Promise( async (resolve, reject) => {
|
|
227
|
+
this.client.hget(dict_key, key, (err, value) => {
|
|
228
|
+
if (err) {
|
|
229
|
+
reject(err);
|
|
230
|
+
if (callback) {
|
|
231
|
+
callback(err, null);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (callback) {
|
|
236
|
+
callback(null, value);
|
|
237
|
+
}
|
|
238
|
+
resolve(value);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
105
242
|
}
|
|
106
243
|
|
|
107
244
|
async getJSON(key, callback) {
|
|
@@ -109,19 +246,16 @@ class TdCache {
|
|
|
109
246
|
return JSON.parse(value);
|
|
110
247
|
}
|
|
111
248
|
|
|
112
|
-
async del(key) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
249
|
+
async del(key, callback) {
|
|
250
|
+
return new Promise( async (resolve, reject) => {
|
|
251
|
+
this.client.del(key, () => {
|
|
252
|
+
if (callback) {
|
|
253
|
+
callback();
|
|
254
|
+
}
|
|
255
|
+
return resolve();
|
|
256
|
+
});
|
|
257
|
+
})
|
|
118
258
|
}
|
|
119
|
-
|
|
120
|
-
// subscribe(key, callback) {
|
|
121
|
-
// this.redis_sub.subscribe(key, (message) => {
|
|
122
|
-
// callback(message);
|
|
123
|
-
// });
|
|
124
|
-
// }
|
|
125
259
|
}
|
|
126
260
|
|
|
127
261
|
module.exports = { TdCache };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.136",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"mongoose": "^6.3.5",
|
|
30
30
|
"multer": "^1.4.5-lts.1",
|
|
31
31
|
"nanoid": "^3.1.25",
|
|
32
|
-
"redis": "^
|
|
32
|
+
"redis": "^3.1.2",
|
|
33
33
|
"uuid": "^3.3.3",
|
|
34
34
|
"vm2": "^3.9.13"
|
|
35
35
|
},
|