0.2.4 • Published 4 years ago

@phiresky/redis-remotify v0.2.4

Weekly downloads
14
License
MIT
Repository
github
Last release
4 years ago

redis-remotify

A tiny library for remote calls and events via redis.

Install via npm:

yarn add @phiresky/redis-remotify

Example use

Say you have a backend like this:

class Squarer {
	public async square(x: number) {
		// maybe do some more interesting stuff here
		return x ** 2;
	}
}

But you want to use the functions it provides in different processes. With this library, you can start a server process like this:

import * as redis from "redis";
import { Listen } from "@phiresky/redis-remotify";

const squarer = new Squarer();

const pub = redis.createClient();
const sub = redis.createClient();
const r = new Listen("backend", { pub, sub });
// add methods to RPC interface with a name like Squarer.square()
r.listenAll(squarer);

And then call the functions from one or more separate node processes like this:

import { Remotify } from "@phiresky/redis-remotify";

const backend = new Remotify("backend", { pub, sub });
const remoteSquarer = backend.remotifyClass(Squarer);
for (const x of [1, 2, 3, 4, 5, 11]) {
	const res = await remoteSquarer.square(x);
	// typeof res is number as expected
	console.log(x, "^2 =", res);
}

Of course it also works with single functions or other non-class objects. A more complete example can be seen in examples/elaborate.ts.

0.2.4

4 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago