📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

pub-sub-handler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pub-sub-handler

Redis Pub/Sub with an object & key on message.

0.0.2
latest
Source
npm
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

Pub Sub Handler

This was written to be used with Redis as a Publish/Subscribe handler. It is just a wrapper designed to help with managing sockets.

Setup:

var psh = require( 'pub-sub-handler' )( { host: localhost, port: 6379 }, function( channel ){
  // Called when the backend Redis makes a subscription
};

Subscribing:

psh.subscribe( 'channel-name', 'key', object, function( channel, key, object, message ){
  // Called when a message is published to the specified channel
};

Publishing:

psh.publish( 'channel-name', 'message' );

Unsubscribing:

psh.unsubscribe( 'channel-name', 'key' );

End:

(kill the Redis connections)

psh.end();

Common Use

A typical use would be the key is a user id and the object is a socket. User connects to a web socket, you subscribe to a specified channel with the user id as a key and pass in the socket as the object. Then in your handler, when a message is published to the channel you have the socket to write the message to.

Keywords

redis

FAQs

Package last updated on 16 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts