npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redular

v1.2.0

Published

Node.js event scheduling system powered by redis keyspace notifications

Downloads

8

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. config set notify-keyspace-events Ex

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

Options

| Key | Value | Default | Description | |------------|---------|------------------------------------------------------|--------------------------------------------------------------------------------------------------| | id | String | Random string | The name of the Redular client, this enables events to only be handled by specific Redis clients | | autoConfig | Boolean | false | When true Redular will attempt to automatically configure Redis | | dataExpiry | Number | 30 | Number of seconds to keep data in Redis for after event has been handled | | redis | Object | port: 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