@product-hackers/neerd

1.1.0 • Public • Published

neerd - Node Event Emitter Redis

Build Status Coverage Status

Neerd is a little wrapper around node_redis pub/sub feature, which essentially emit events to other node modules on subscriptions messages.

Install

npm i --save @product-hackers/neerd

Usage

const Neerd = require('@product-hackers/neerd');

// All config from node_redis is available to pass in the constructor.
// See https://github.com/NodeRedis/node_redis
const redisConfig = {
  host: 'localhost',
  port: 6379,
};

const neerd = new Neerd(redisConfig);

neerd.on('connection', async (message) => {
  console.log(`Connected: ${message}`);
  testSub();
  testPub();
});

neerd.on('error', (error) => {
  console.error(`There was an error connecting to redis: ${error}`);
});

const testSub = () => {
  neerd.on('test-channel', (message) => {
    console.log(`Message received on test-channel: ${message}`);
  });
  neerd.startSub('test-channel');
};

const testPub = (message = '') => {
  const neerdPub = new Neerd(redisConfig);
  neerdPub.publish('test-channel', 'This is a test message sent via redis pubsub');
  neerdPub.publish('test-channel', JSON.stringify({ message: 'You can also serialize messages' }));
};

Testing

Running npm t builds the library, runs the tests and report coverage.

License

MIT.

Package Sidebar

Install

npm i @product-hackers/neerd

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

6.81 kB

Total Files

5

Last publish

Collaborators

  • conti00
  • jorchgg
  • ph-jorch