@craftnotion/adonisjs-advance-redis-rpc
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@craftnotion/adonisjs-advance-redis-rpc

Adonis, Adonisjs, Redis RPC

npm-image license-image typescript-image

The @craftnotion/adonisjs-advance-redis-rpc package is a powerful RPC (Remote Procedure Call) provider designed specifically for AdonisJS applications. It leverages Redis pub/sub transport for efficient communication between server and client instances. This package simplifies the implementation of distributed systems by enabling seamless communication between different parts of your application.

Installation

Before installing the package, ensure you have Redis installed and configured. You can follow the instructions provided in the AdonisJS documentation for setting up Redis.

Once Redis is set up, you can install the package via npm:

npm i @craftnotion/adonisjs-advance-redis-rpc
node ace configure @craftnotion/adonisjs-advance-redis-rpc

Usage

The server, methods, and client can be initiated in a preload file to ensure seamless communication within your AdonisJS application. Execute the following command to create a preload file:

node ace make:prldfile redis_rps

Server Mode

In server mode, you can create a server with a specific name and add handlers for methods that can be invoked remotely.

import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'

async run(){

  await redisRPC.server('example') // Create a server with name example

  redisRPC.addHandler('exampleMethod', async ({ data }) => {
    console.log(data);
  })

}

run();

Client mode

import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'

async run(){

  await redisRPC.clinet() // Create a server with name example
}

run();

Calling methods

import Route from '@ioc:Adonis/Core/Route'
import redisRPC from '@craftnotion/adonisjs-advance-redis-rpc/services/main'

Route.get('example', async () => {
  const result = await redisRPC.call('example.exampleMethod', { data: 'message' })
  return result
})

Crafted with ❤️ by Craftnotion

Package Sidebar

Install

npm i @craftnotion/adonisjs-advance-redis-rpc

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

25.9 kB

Total Files

25

Last publish

Collaborators

  • shus_himanshu