-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstk.js
63 lines (54 loc) · 1.48 KB
/
stk.js
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
60
61
62
63
"use strict";
var redis = require('redis').createClient();
redis.on("error", function(err) {
console.error('Redis client error:', err);
});
const _idNames = {};
const _idHistories = {};
// used by the eval(reply) on redis retrun
function historySearchHandler(info) {
return info;
}
function getHistory(keys, i) {
if (i < keys.length) {
var stockId = keys[i];
redis.get(stockId, function (err, reply) {
if (!err) {
try {
var evo = eval(reply);
_idHistories[stockId] = evo[0].hq;
}
catch (ex) {
console.log(stockId, " ", ex, " when parsing ", reply);
_idHistories[stockId] = null;
}
}
else {
console.error("Error get history from redis on:" + stockId);
}
getHistory(keys, i+1);
});
}
}
function getHistories() {
var keys = [];
for (let stockId in _idNames) {
keys.push(stockId);
}
getHistory(keys, 0);
}
function getIdAndNames() {
redis.hgetall("_stockId2Name", function(err, idNames) {
if (idNames) {
for (let k in idNames) {
_idNames[k] = idNames[k];
}
getHistories();
} else {
console.error('Can not read _stockId2Name. Error:', err);
}
});
};
//getIdAndNames();
exports._idNames = _idNames;
exports._idHistories = _idHistories;