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

redis-pubsub-manager

v1.0.1

Published

Redis (Pub/Sub) Manager to Events http://redis.js.org/#api-publish-subscribe

Downloads

3

Readme

Usage of RedisPubSub to Events

NPM version Downloads Build Status Coverage Status

This is a small library, convert callback Subscriptions to events

Installation

npm i redis-pub-sub-manager

or

npm i -D redis-pub-sub-manager

Example

Using native implementation of redis library

Traditionally when subscribing an event when a message arrives we have 2 variables, the channel and the message. So we must always ask for the channel before executing a specific action for that channel.

So we must add a couple of additional lines in our code and we can only send flat messages; so we must encode and decode when sending and receiving a message.

We must also create a connection to publish and another to subscribe.

const Redis = require('redis');
const Publisher  = Redis.createClient(...optionsOfRedis); //View  https://www.npmjs.com/package/redis#rediscreateclient
const Subscriber = Redis.createClient(...optionsOfRedis); //View https://www.npmjs.com/package/redis#rediscreateclient

//To listen a event
Subscriber.subscribe("AEventName");
Subscriber.on('message',(Chanel, PlainMessage) => {
    if(Chanel==="AEventName"){
        //Any action
        console.log(JSON.parse(PlainMessage));
    }
});

//To publish
Publisher.publish('AEventName',JSON.stringify({Other:15, Msg:'Hello World!'}));

//To stop receive messages
Subscriber.unsubscribe("AEventName");

Using this library

Custom events, multiple callbacks for the same event, supports flat messages and objects.

You write less code.

const RedisPubSub = require('redis-pubsub-manager');
const redisPubSub = new RedisPubSub(...optionsOfRedis); //View https://www.npmjs.com/package/redis#rediscreateclient

//Add bind action to event
redisPubSub.on("AEventName",(Message)=>{
    console.log(Message); //Object or String
});

//To publish
redisPubSub.publish("AEventName",{Other:15, Msg:'Hello World!'});

//To stop receive messages
redisPubSub.unbind("AEventName");