adonis5-redis-rpc
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

adonis5-redis-rpc

Adonis, Adonis 5, Redis RPC

npm-image license-image typescript-image

Simple RPC Provider for Adonis 5, based on Redis pub/sub transport

Installation

npm i adonis5-redis-rpc
node ace invoke adonis5-redis-rpc

Usage

Server mode

You can create adonis command (node ace make:command RPCServer) like this:

import { BaseCommand } from '@adonisjs/core/build/standalone'
import RedisRPC from '@ioc:Adonis/Addons/RedisRPC'

export default class VangaPlaincalc extends BaseCommand {
  /**
   * Command name is used to run the command
   */
  public static commandName = 'vanga:plaincalc'

  /**
   * Command description is displayed in the "help" output
   */
  public static description = ''

  public static settings = {
    /**
     * Set the following value to true, if you want to load the application
     * before running the command
     */
    loadApp: true,

    /**
     * Set the following value to true, if you want this command to keep running until
     * you manually decide to exit the process
     */
    stayAlive: false,
  }

  public async run() {
    this.logger.info('Hello world!')
    await RedisRPC.server()
    RedisRPC.addHandler<{}>('exampleMethod', async (payload) => {
      console.log(payload)
      return {success: true}
    })
  }
}

Client mode

import Route from '@ioc:Adonis/Core/Route'
import RedisRPC from '@ioc:Adonis/Addons/RedisRPC'
Route.get('example', () => {
  await RedisRPC.client()
  const result =  await RedisRPC.call('exampleMethod', {data: 'message'})
  return result
})

Package Sidebar

Install

npm i adonis5-redis-rpc

Weekly Downloads

21

Version

1.0.3

License

MIT

Unpacked Size

11.5 kB

Total Files

11

Last publish

Collaborators

  • beatlelab