New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

redis-ipc

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-ipc

Simple redis pub/sub module. Two redis client instances in one object.

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

============ redis-ipc

Simple package to publish/subscribe to IPC channels.

Main purpose of this module is to create separate publish/subscribe redis client instances in one object.

With redis client you would work with subscribe/publish in the next way:

.. code-block:: javascript

var redis = require("redis");
var sub = redis.createClient(), pub = redis.createClient();
var msg_count = 0;

sub.on("subscribe", function (channel, count) {
    pub.publish("a nice channel", "I am sending a message.");
    pub.publish("a nice channel", "I am sending a second message.");
    pub.publish("a nice channel", "I am sending my last message.");
});

sub.on("message", function (channel, message) {
    console.log("sub channel " + channel + ": " + message);
    msg_count += 1;
    if (msg_count === 3) {
        sub.unsubscribe();
        sub.quit();
        pub.quit();
    }
});

sub.subscribe("a nice channel");

So, we combine this two redis client instances in one object and expose functions to publish, subscribe and return EventEmitter for incoming messages:

.. code-block:: javascript

const IPC = require('redis-ipc');

let myIPC = IPC({
  debug: false
});

myIPC.on('connect', _ => {
  console.log('connect event');
  myIPC
    .subscribe('0x00/playback/state')
    .on('subscribe', _ => {
      myIPC
        .publish('0x00/playback/state', "Hello, friend");
    })
    .on('message', message => {
      console.log(`got message: ${message}`);
      myIPC
        .unsubscribe('0x00/playback/state');

      myIPC
        .subscribe('hello')
        .on('subscribe', _ => {
          myIPC
            .publish('hello', 'friend');
        })
        .on('message', message => {
          console.log(`another message: ${message}`);
        })
    });
});


myIPC.on('error', err => {
  console.log(`err ${err}`)
});

myIPC.connect();

Keywords

redis

FAQs

Package last updated on 09 Jul 2018

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