1.0.7 • Published 5 years ago
redis-crontab v1.0.7
redis-crontab
redis-crontab is for interval-based sheduling.It based on Redis, Multi-threaded security.
Install
you can install it via npm:
npm install --save redis-crontab
Usage
Redis Keyspace Notification is RedisCrontab's principle. So your redis version must >=2.8 .
By default keyspace events notifications are disabled.
Notifications are enabled using the notify-keyspace-events of redis.conf :notify-keyspace-events Ex
.(about notifications)
Then ,you can use it:
//import
import RedisCrontab from 'redis-crontab';
//new
let task = new RedisCrontab({
redis_address: '', // redis url
redis_db : 0,// select db num
});
// init interval task ,it will run once ervery two seconds
task.initTask('sys:test', function() {
console.log('test task');
throw new Error('test error');
}, 2);
// int one-time task , it will run after 60 seconds
task.initOnceTask('sys:once:task',function(){
console.log('it is a once task');
},60);
Params
options.redis_address
: the redis url,just like :redis://127.0.0.1:6379/0
options.redis_db
: the selected db number,default is0
options.safe_lock_expire
: RedisCrontab is Multi-threaded security, so you can set the lock expire time ,default is60
seconds. When it set0
,it will not set multi lock.
API
initTask( redis_key_symbol , task_func , time_interval )
: init interval task ,it will runtask_func
once erverytime_interval
secondsinitOnceTask( redis_key_symbol , task_func ,time_interval)
: int one-time task , it will runtask_func
aftertime_interval
seconds
version
- 1.0.4 add
initOnceTask
function for run once task. - 1.0.3 fix some bugs.