redis-crontab

1.0.7 • Public • Published

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 is 0
  • options.safe_lock_expire : RedisCrontab is Multi-threaded security, so you can set the lock expire time ,default is 60 seconds. When it set 0,it will not set multi lock.

API

  • initTask( redis_key_symbol , task_func , time_interval ): init interval task ,it will run task_func once ervery time_interval seconds

  • initOnceTask( redis_key_symbol , task_func ,time_interval): int one-time task , it will run task_func after time_interval seconds

version

  • 1.0.4 add initOnceTask function for run once task.
  • 1.0.3 fix some bugs.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.7
    2
    • latest

Version History

Package Sidebar

Install

npm i redis-crontab

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

17.1 kB

Total Files

8

Last publish

Collaborators

  • guanmac