-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 1.11 KB
/
index.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
const
numberOfRecords = process.argv[2] || 100,
carBrands = require('./testdata.js');
/**
* Waits for the specified number of milliseconds.
*
* @param {number} milliseconds - The number of milliseconds to wait.
* @returns {Promise<void>} - A promise that resolves after the specified number of milliseconds.
*/
function wait(milleseconds) {
return new Promise(resolve => setTimeout(resolve, milleseconds))
}
/**
* Generates records with Redis commands asynchronously.
*
* @returns {Promise<void>} A promise that resolves when all records are generated.
*/
async function generateRecords() {
const promises = Array.from({ length: numberOfRecords }, async (_, i) => {
await wait(10);
const randomBrandIndex = Math.floor(Math.random() * carBrands.length);
const ts = (new Date()).getTime() + i + randomBrandIndex;
const _brand = carBrands[randomBrandIndex];
console.log(`HSET brandRankMonth:${ts} timestamp ${ts} brand "${_brand}"`);
console.log(`EXPIRE brandRankMonth:${ts} ${86400 - randomBrandIndex} NX\n`);
});
await Promise.all(promises);
}
(async () => {
await generateRecords();
})();