Skip to content

Neerd is a wrapper around node_redis pub/sub and node EventEmitter

License

Notifications You must be signed in to change notification settings

ProductHackers/neerd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published