Socket
Book a DemoInstallSign in
Socket

redis-psp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-psp

Redis Pub Sub with promises

latest
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

RedisPsp

Easy way to subscribe and publish (at the cost of opening/closing connections)

Repo

https://github.com/david-wu/redisPubSubPromise

Installation

npm install --save redis-psp

Usage

const redisPsp = require('redis-psp')

function startServices(){
	return Promise.all([
		doublingService(),
		greetingService(),
		delayedEchoService(),
	])
}

function doublingService(){
	return redisPsp.onP('double', function(num){
		return num*2
	})
}

function greetingService(){
	return redisPsp.onP('greet', function(name){
		return 'Hello, '+name
	})
}

function delayedEchoService(){
	return redisPsp.onP('delayedEcho', function(data){
		return new Promise(function(resolve, reject){
			setTimeout(function(){
				resolve(data.text)
			}, data.delay)
		})
	})
}


startServices()
	.then(function(){

		redisPsp.emitP('double', 2)
			.then(function(response){
				console.log('doubled:', response);
			})

		redisPsp.emitP('greet', 'Maggie')
			.then(function(response){
				console.log('greeted:', 'Maggie');
			})

		redisPsp.emitP('delayedEcho', {text: 'myText', delay: 3000})
			.then(function(response){
				console.log('delayed text:', response)
			})

	})

FAQs

Package last updated on 29 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts