The Layotto Node.js SDK to build your application.
demo/state.ts
import { Client } from 'layotto';
const storeName = 'redis';
const key = 'foo-js-sdk';
const value = `bar, from js-sdk, ${Date()}`;
await client.state.save({
storeName,
states: { key, value },
});
console.log('saveState success, key: %j, value: %j', key, value);
const resValue = await client.state.get({ storeName, key });
console.log('getState success, key: %j, value: %j, toString: %j',
key, resValue, Buffer.from(resValue).toString('utf8'));
npm install
Should install grpc-tools first. MacOS M1 follow this issue.
npm install grpc-tools
npm run build:grpc
- Running redis under Docker
docker pull redis:latest
docker run -itd --name redis-test -p 6380:6379 redis
- Running etcd under Docker
docker pull quay.io/coreos/etcd
docker run -itd -p 2379:2379 --name etcd quay.io/coreos/etcd /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379
- Start a echoserver for testing the rpc api
go run demo/rpc/http/echoserver/echoserver.go
If you want to know more about this,check https://mosn.io/layotto/#/zh/start/rpc/helloworld
- Start Layotto, see How to run layotto
git clone https://github.com/mosn/layotto.git
cd layotto/cmd/layotto
go build
./layotto start -c ../../configs/config_redis.json
- Then, run the test script by npm
npm run test:unit
Enable trace debug log for grpc-js:
GRPC_TRACE=compression GRPC_VERBOSITY=debug GRPC_TRACE=all npm run test test/unit/client/Invoker.test.ts