Skip to content

dimailn/redis-pubsub-rpc

Repository files navigation

redis-pubsub-rpc

Build Status Coverage Status

This library provide lightweight RPC layer over Redis Pub/Sub.

Installation

npm install --save redis-pubsub-rpc

Getting started

Register handler in server application

import {Server} from 'redis-pubsub-rpc'

const server = new Server('redis://127.0.0.1:6379')

server.addHandler('string.uppercase', (message) => message.toUpperCase())

And call the method from a client

import {Client} from 'redis-pubsub-rpc'

const client = new Client('redis://127.0.0.1:6379')

client.call('string.uppercase', ['text']).then(console.log) // Prints 'TEXT'

You may also specify serverId and communicate with many servers in one application

// create server with id
const server = new Server('redis://127.0.0.1:6379', {
  serverId: 'worker-0',
  applicationName: 'example'
})

const client = new Client('redis://127.0.0.1:6379', {
  applicationName: 'example'
})

// and specify serverId in call invocation

client.call('string.uppercase', ['text'], 'worker-0')

If you need to remove handler

server.removeHandler('string.uppercase')

To shutdown client and server call method quit()

client.quit()
server.quit()

About

Adressable JSON RPC over Redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published