red

redular

Node.js event scheduling system powered by Redis keyspace notifications

Showing:

Popularity

Downloads/wk

15

GitHub Stars

9

Maintenance

Last Commit

6yrs ago

Contributors

1

Package

Dependencies

2

Size (min+gzip)

12.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Readme

redular Build Status

Node.js event scheduling system powered by Redis keyspace notifications.

This is a work in progress

NPM

How it works

This sets keys in redis with expiry times, then using the keyspace notifications triggers handlers defined in your code.

This is useful because it means you can define handlers and trigger them from anywhere in your infrastructure.

Installation

$ npm install redular

This module requires at least version 2.8.0 of Redis You must enable Keyspace Notifications (Specifically expiry)

You can use the following command inside redis-cli to enable expiry keyspace notificaitons.

127.0.0.1:6379> config set notify-keyspace-events Ex

Alternatively you can set autoConfig to true in the Redular options to attempt to automatically configure Redis.

Options

KeyValueDefaultDescription
idStringRandom stringThe name of the Redular client, this enables events to only be handled by specific Redis clients
autoConfigBooleanfalseWhen true Redular will attempt to automatically configure Redis
dataExpiryNumber30Number of seconds to keep data in Redis for after event has been handled
redisObjectport: 6379, host:'localhost'See here for more options

Basic Usage

var Redular = require('redular');

var options = {
  redis : {
    port: 6379,
    host: 'localhost'
  }
}

//Setup Redular
var myRedular = new Redular(options);

//Define a handler for an event
myRedular.defineHandler('test-event', function(){
    console.log('Test event!');
})

//Schedule the event to happen 5 seconds in the future
var date = new Date();
date.setSeconds(date.getSeconds() + 5);
myRedular.scheduleEvent('test', date);

Global vs Non-Global Events

When scheduling an event you can pass in a boolean to specify if an event should be handled globally or not

//This is a global event
myRedular.scheduleEvent('my-event', date, true);

//This is a non-global event
myRedular.scheduleEvent('my-event', date, false);

Global

Global events are handled by all available handlers that match the event name and are listening for keyspace notifications.

Non-global

This is the default event type, they are only processed by handlers defined by the same Redular instance that scheduled them.

Passing data to handlers

It is possible to pass data to your handlers like so

myRedular.defineHandler('greet', function(someData){
    console.log('Hello ' + someData.name);
})

myRedular.scheduleEvent('greet', date, false, {name: 'Joe'});

There are a few caveats with this:
The data is stored in Redis as a JSON string so you cannot send functions to handlers.
Data is passed through a JSON.stringify() before being saved to Redis, bear this in mind.

Instant events

You can send an event to Redular for immediate handling by using the instantEvent function

myRedular.instantEvent('greet', false, {name: 'Joe'})

The options are the same as the scheduleEvent function but without passing a date object

Testing

$ npm install
$ npm test

Tests are built with mocha

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

agendaLightweight job scheduling for Node.js
User Rating
4.8/ 5
5
Top Feedback
5Easy to Use
4Performant
3Highly Customizable
GitHub Stars
8K
Weekly Downloads
67K
agenda-restScheduling as a Service
User RatingN/A
Top Feedback
N/A
GitHub Stars
104
Weekly Downloads
21
node-cronA simple cron-like job scheduler for Node.js
User Rating
4.8/ 5
13
Top Feedback
9Great Documentation
9Easy to Use
9Performant
GitHub Stars
2K
Weekly Downloads
309K
sch
schedulingA enterframe tool
User RatingN/A
Top Feedback
N/A
GitHub Stars
0
Weekly Downloads
28
bree:traffic_light: The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.
User RatingN/A
Top Feedback
4Great Documentation
3Easy to Use
3Performant
GitHub Stars
1K
Weekly Downloads
13K
See 14 Alternatives

Tutorials

No tutorials found
Add a tutorial