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