forked from rpp32-sdc-saline/questions_answers-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachePrep.js
37 lines (31 loc) · 814 Bytes
/
cachePrep.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
const client = require('./redis.js');
const db = require('./database/indexDB.js');
(async () => {
console.log('connecting client')
await client.connect();
})();
client.on('error', (err) => console.log('Redis Client Error: ', err));
const randomProduct = () => {
const idStart = 700000;
const idEnd = 1000011;
return ((Math.floor(Math.random() * (idEnd - idStart))) + idStart);
}
const cacheValue = async (counter) => {
const randomId = Number(randomProduct());
const randomValue = await db.allData(randomId);
await client.set(randomId, randomValue);
if (counter % 100) {
console.log(counter);
}
return;
}
const warmCache = async () => {
var counter = 0;
while (counter < 70000) {
cacheValue(counter);
counter++;
}
console.log('All done!');
return;
};
warmCache();