Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 1.96 KB

README.md

File metadata and controls

67 lines (48 loc) · 1.96 KB

@superbalist/js-pubsub-redis

A Redis adapter for the js-pubsub package.

Author Build Status Software License NPM Version NPM Downloads

Installation

npm install @superbalist/js-pubsub-redis

Usage

'use strict';

let redis = require('redis');
let RedisPubSubAdapter = require('@superbalist/js-pubsub-redis');

let client = redis.createClient({
  host: 'redis',
  port: 6379
});

let adapter = new RedisPubSubAdapter(client);

// consume messages
// note: this is a blocking call
adapter.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish messages
adapter.publish('my_channel', {first_name: 'Matthew'});
adapter.publish('my_channel', 'Hello World');

// publish multiple messages
let messages = [
  'message 1',
  'message 2',
];
adapter.publishBatch('my_channel', messages);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts.

Run make up.

You will start at a bash prompt in the /usr/src/app directory.

If you need another shell to publish a message to a blocking consumer, you can run docker-compose run js-pubsub-redis /bin/bash

To run the examples:

$ node examples/RedisConsumerExample.js
$ node examples/RedisPublishExample.js (in a separate shell)