Code Monkey home page Code Monkey logo

neerd's Introduction

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.

neerd's People

Contributors

dependabot[bot] avatar jorchg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.