1.0.0 • Published 7 years ago
cronjob-notification-redis v1.0.0
��# Redis notification hashes for CronJob push notification A lightway notification hash for Nodejs that create schedule push notification every time define.
Features
- Create hashes for notifications(key, message) to push notification to mobile, web ...
- Method pushNotification and handleError is define external.
- User can define time interval for schedule. Every time interval define, system get all notification and push them to devices via function pushNotification which user define.
Install
npm install cron-noti-redis
Examples
Initialize
RedisSN = require('cron-noti-redis');
Create a hashes
Create a hashes with pre-define method pushNotification and handeError
Parameters:
push
: function push notificationhandle
: handle error of hashesoptions
: optional{ name: "RedisCNQ", redisOptions: { host: "127.0.0.1", port: 6379 }, schedule: { hour: '*', minute: '*' } }
function handle(err) {
console.log('ERROR: ' + err.message);
}
function push(q) {
// Push notification to devices in here.
let time = new Date(Date.now());
if (!q) {
console.log(time + ' : Queue empty.');
}
_.forEach(q, function(val, key) {
console.log(time + ' : ', key, val);
});
}
const schedule = new RedisSN(push, handle, options);
Add notification to hashes
Add notification to hashses if key exist, old message will be replaced
schedule.addNotification('userId1', 'XYZ.ABC : Your have new message from friend.');
Remove notification to hashes
Remove notification in hashes
schedule.removeNotification('userId1');
Push notification
Push all notification in hashes and remove them from hash
Note: this function will be automatic called in cronjob.
schedule.pushNotification();
1.0.0
7 years ago