Skip to content

A Redis adapter for the js-pubsub package

License

Notifications You must be signed in to change notification settings

Superbalist/js-pubsub-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

71e24cb · May 17, 2017

History

13 Commits
May 15, 2017
May 17, 2017
May 17, 2017
May 2, 2017
May 4, 2017
May 9, 2017
May 9, 2017
May 8, 2017
May 9, 2017
May 2, 2017
May 2, 2017
May 17, 2017
May 17, 2017
May 2, 2017
May 17, 2017

Repository files navigation

@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)