unpkg/modules/utils/incrementCounter.js

16 lines
319 B
JavaScript
Raw Normal View History

2018-12-17 17:38:05 +00:00
const db = require('./data');
2018-05-26 00:25:04 +00:00
function incrementCounter(counter, key, by = 1) {
return new Promise((resolve, reject) => {
db.hincrby(counter, key, by, (error, value) => {
if (error) {
2018-02-18 02:00:56 +00:00
reject(error);
} else {
2018-02-18 02:00:56 +00:00
resolve(value);
}
2018-02-18 02:00:56 +00:00
});
});
}
2018-02-18 02:00:56 +00:00
module.exports = incrementCounter;