https://github.com/reg2005/adonis5-redis-rpc
Simple RPC Provider for Adonis 5, based on Redis pub/sub transport
https://github.com/reg2005/adonis5-redis-rpc
Last synced: 5 months ago
JSON representation
Simple RPC Provider for Adonis 5, based on Redis pub/sub transport
- Host: GitHub
- URL: https://github.com/reg2005/adonis5-redis-rpc
- Owner: reg2005
- License: mit
- Created: 2021-06-16T12:36:27.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-15T06:42:54.000Z (over 2 years ago)
- Last Synced: 2025-05-04T16:02:09.557Z (about 1 year ago)
- Language: TypeScript
- Size: 126 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-adonisjs - Adonis Redis RPC - Simple RPC Provider for Adonis 5, based on Redis pub/sub transport (Packages)
README
# adonis5-redis-rpc
> Adonis, Adonis 5, Redis RPC
[![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
Simple RPC Provider for Adonis 5, based on Redis pub/sub transport
## Installation
Setup redis from [this manual](https://docs.adonisjs.com/guides/redis)
and
```bash
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:
```ts
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
```ts
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
})
```
[npm-image]: https://img.shields.io/npm/v/adonis5-redis-rpc.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/adonis5-redis-rpc "npm"
[license-image]: https://img.shields.io/npm/l/adonis5-redis-rpc?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"