task-archive.js
1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const redis = require("redis");
const config = require('../config');
let redis_client;
function init() {
if (!config.redis) {
return;
}
redis_client = redis.createClient(config.redis);
}
function keyword(task) {
return 'geckoo_' + config.handler_name + '_' + task.trx_id;
}
function put(task) {
if (!redis_client) {
return;
}
const keyword = keyword(task);
redis_client.set(keyword, JSON.stringify(task));
redis_client.expire(keyword, 3600 * 24 * 15);
}
function get(task, cb) {
if (!redis_client) {
cb(null);
return;
}
redis_client.get(keyword(task), function(res) {
if (!res) {
cb(null);
}
else {
let resObj;
try {
resObj = JSON.parse(res);
}
catch(e) {
cb(null);
return;
}
cb(resObj);
}
});
}
init();
exports.put = put;
exports.get = get;